CF1178G.The Awesomest Vertex
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a rooted tree on n vertices. The vertices are numbered from 1 to n ; the root is the vertex number 1 .
Each vertex has two integers associated with it: ai and bi . We denote the set of all ancestors of v (including v itself) by R(v) . The awesomeness of a vertex v 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 n and q ( 1≤n≤2⋅105,1≤q≤105 ) — the number of vertices in the tree and the number of queries, respectively.
The second line contains n−1 integers p2,p3,…,pn ( 1≤pi<i ), where pi means that there is an edge between vertices i and pi .
The third line contains n integers a1,a2,…,an ( −5000≤ai≤5000 ), the initial values of ai for each vertex.
The fourth line contains n integers b1,b2,…,bn ( −5000≤bi≤5000 ), the values of bi for each vertex.
Each of the next q lines describes a query. It has one of the following forms:
- 1 v x ( 1≤v≤n , 1≤x≤5000 ).
- 2 v ( 1≤v≤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] . The most awesome vertex in the subtree of vertex 1 (the first query) is 1 , and the most awesome vertex in the subtree of vertex 2 (the second query) is 2 .
After the first update (the third query), the awesomeness changes to [100,169,57,160,57] and thus the most awesome vertex in the whole tree (the fourth query) is now 2 .
After the second update (the fifth query), the awesomeness becomes [100,234,57,240,152] , hence the most awesome vertex (the sixth query) is now 4 .