CF1178G.The Awesomest Vertex

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a rooted tree on nn vertices. The vertices are numbered from 11 to nn ; the root is the vertex number 11 .

Each vertex has two integers associated with it: aia_i and bib_i . We denote the set of all ancestors of vv (including vv itself) by R(v)R(v) . The awesomeness of a vertex vv is defined as

$$\left| \sum_{w \in R(v)} a_w\right| \cdot \left|\sum_{w \in R(v)} b_w\right|, $$ </p><p>where $|x|$ denotes the absolute value of $x$ . </p><p>Process $q$ queries of one of the following forms: </p><ul> <li> <span class="tex-font-style-tt">1 v x</span> — increase $a\_v$ by a positive integer $x$ . </li><li> <span class="tex-font-style-tt">2 v</span> — report the maximum <span class="tex-font-style-it">awesomeness</span> in the subtree of vertex $v$$$.

输入格式

The first line contains two integers nn and qq ( 1n2105,1q1051 \leq n \leq 2\cdot 10^5, 1 \leq q \leq 10^5 ) — the number of vertices in the tree and the number of queries, respectively.

The second line contains n1n - 1 integers p2,p3,,pnp_2, p_3, \dots, p_n ( 1pi<i1 \leq p_i < i ), where pip_i means that there is an edge between vertices ii and pip_i .

The third line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 5000ai5000-5000 \leq a_i \leq 5000 ), the initial values of aia_i for each vertex.

The fourth line contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n ( 5000bi5000-5000 \leq b_i \leq 5000 ), the values of bib_i for each vertex.

Each of the next qq lines describes a query. It has one of the following forms:

  • 1 v x ( 1vn1 \leq v \leq n , 1x50001\leq x \leq 5000 ).
  • 2 v ( 1vn1 \leq v \leq n ).

输出格式

For each query of the second type, print a single line with the maximum awesomeness in the respective subtree.

输入输出样例

  • 输入#1

    5 6
    1 1 2 2
    10 -3 -7 -3 -10
    10 3 9 3 6
    2 1
    2 2
    1 2 6
    2 1
    1 2 5
    2 1
    

    输出#1

    100
    91
    169
    240
    

说明/提示

The initial awesomeness of the vertices is [100,91,57,64,57][100, 91, 57, 64, 57] . The most awesome vertex in the subtree of vertex 11 (the first query) is 11 , and the most awesome vertex in the subtree of vertex 22 (the second query) is 22 .

After the first update (the third query), the awesomeness changes to [100,169,57,160,57][100, 169, 57, 160, 57] and thus the most awesome vertex in the whole tree (the fourth query) is now 22 .

After the second update (the fifth query), the awesomeness becomes [100,234,57,240,152][100, 234, 57, 240, 152] , hence the most awesome vertex (the sixth query) is now 44 .

首页