CF1178G.The Awesomest Vertex
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:256MB
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_winR(v)a_wright∣cdotleft∣sum_winR(v)b_wright∣,
where ∣x∣ denotes the absolute value of x.
Process q queries of one of the following forms:
- 1 v x — increase av by a positive integer x.
- 2 v — report the maximum awesomeness in the subtree of vertex v.
给你一棵有 n 个顶点的有根树。顶点编号为 1 到 n;根节点为顶点 1。
每个顶点 i 关联两个整数:ai 和 bi。记 v 的所有祖先(包括 v 自身)构成的集合为 R(v)。顶点 v 的“卓越值”(awesomeness)定义为:
w∈R(v)∑aw⋅w∈R(v)∑bw,
其中 ∣x∣ 表示 x 的绝对值。
你需要处理 q 个查询,查询类型如下:
1 v x— 将 av 增加一个正整数 x;2 v— 输出顶点 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).
第一行包含两个整数 n 和 q(1≤n≤2⋅105,1≤q≤105)—— 分别表示树中顶点的数量和查询的数量。
第二行包含 n−1 个整数 p2,p3,…,pn(1≤pi<i),其中 pi 表示顶点 i 与顶点 pi 之间存在一条边。
第三行包含 n 个整数 a1,a2,…,an(−5000≤ai≤5000),表示每个顶点的初始值 ai。
第四行包含 n 个整数 b1,b2,…,bn(−5000≤bi≤5000),表示每个顶点的值 bi。
接下来的 q 行每行描述一个查询,其格式为以下两种之一:
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.
顶点的初始“酷炫值”为 [100,91,57,64,57]。在顶点 1 的子树中(第一个查询),最酷炫的顶点是 1;在顶点 2 的子树中(第二个查询),最酷炫的顶点是 2。
第一次更新后(第三个查询),酷炫值变为 [100,169,57,160,57],因此整棵树中最酷炫的顶点(第四个查询)现在是 2。
第二次更新后(第五个查询),酷炫值变为 [100,234,57,240,152],因此最酷炫的顶点(第六个查询)现在是 4。
输入解题思路,AI测评打分。不知道怎么写?