CF1178G.The Awesomest Vertex

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

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_winR(v)a_wright∣cdotleft∣sum_winR(v)b_wright∣,\\left| \\sum\_{w \\in R(v)} a\_w\\right| \\cdot \\left|\\sum\_{w \\in R(v)} b\_w\\right|,

where ∣x∣|x| denotes the absolute value of xx.

Process qq queries of one of the following forms:

  • 1 v x — increase ava_v by a positive integer xx.
  • 2 v — report the maximum awesomeness in the subtree of vertex vv.

给你一棵有 nn 个顶点的有根树。顶点编号为 11 到 nn;根节点为顶点 11。

每个顶点 ii 关联两个整数:aia_i 和 bib_i。记 vv 的所有祖先(包括 vv 自身)构成的集合为 R(v)R(v)。顶点 vv 的“卓越值”(awesomeness)定义为:

∣∑w∈R(v)aw∣⋅∣∑w∈R(v)bw∣,\left| \sum_{w \in R(v)} a_w\right| \cdot \left|\sum_{w \in R(v)} b_w\right|,

其中 ∣x∣|x| 表示 xx 的绝对值。

你需要处理 qq 个查询,查询类型如下:

  • 1 v x — 将 ava_v 增加一个正整数 xx;
  • 2 v — 输出顶点 vv 的子树中所有顶点的最大卓越值。

输入格式

The first line contains two integers nn and qq (1≤n≤2⋅105,1≤q≤1051 \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 n−1n - 1 integers p2,p3,…,pnp_2, p_3, \dots, p_n (1≤pi<i1 \leq p_i \lt 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 (−5000≤ai≤5000-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 (−5000≤bi≤5000-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  (1≤v≤n1 \leq v \leq n, 1≤x≤50001\leq x \leq 5000).
  • 2 v  (1≤v≤n1 \leq v \leq n).

第一行包含两个整数 nn 和 qq(1≤n≤2⋅1051 \leq n \leq 2\cdot 10^5,1≤q≤1051 \leq q \leq 10^5)—— 分别表示树中顶点的数量和查询的数量。

第二行包含 n−1n - 1 个整数 p2,p3,…,pnp_2, p_3, \dots, p_n(1≤pi<i1 \leq p_i \lt i),其中 pip_i 表示顶点 ii 与顶点 pip_i 之间存在一条边。

第三行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(−5000≤ai≤5000-5000 \leq a_i \leq 5000),表示每个顶点的初始值 aia_i。

第四行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(−5000≤bi≤5000-5000 \leq b_i \leq 5000),表示每个顶点的值 bib_i。

接下来的 qq 行每行描述一个查询,其格式为以下两种之一:

  • 1 v x(1≤v≤n1 \leq v \leq n,1≤x≤50001\leq x \leq 5000)。
  • 2 v(1≤v≤n1 \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.

顶点的初始“酷炫值”为 [100,91,57,64,57][100, 91, 57, 64, 57]。在顶点 11 的子树中(第一个查询),最酷炫的顶点是 11;在顶点 22 的子树中(第二个查询),最酷炫的顶点是 22。

第一次更新后(第三个查询),酷炫值变为 [100,169,57,160,57][100, 169, 57, 160, 57],因此整棵树中最酷炫的顶点(第四个查询)现在是 22。

第二次更新后(第五个查询),酷炫值变为 [100,234,57,240,152][100, 234, 57, 240, 152],因此最酷炫的顶点(第六个查询)现在是 44。

输入解题思路,AI测评打分。不知道怎么写?

首页