AT_abc460_g.Vertex Flip Query

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There is a tree with NN vertices numbered 11 to NN. The ii-th edge connects vertices aia_i and bib_i. Each vertex ii has a weight WiW_i and a color Ci∈{0,1}C_i \in \lbrace 0,1 \rbrace.
Process QQ queries. There are three types of queries as follows.

  • 1 v: Change CvC_v to 1−Cv1 - C_v for vertex vv.
  • 2 v x: Change WvW_v to Wv+xW_v + x for vertex vv.
  • 3 v: Let cc be the color of vertex vv. Output the sum of weights of all vertices reachable from vertex vv by traveling only through vertices of color cc (including vertex vv itself).

有一棵包含 NN 个顶点的树,顶点编号为 11 到 NN。第 ii 条边连接顶点 aia_i 和 bib_i。每个顶点 ii 具有权重 WiW_i 和颜色 Ci∈{0,1}C_i \in \lbrace 0,1 \rbrace。
处理 QQ 个查询。查询共分以下三种类型:

  • 1 v:将顶点 vv 的颜色 CvC_v 修改为 1−Cv1 - C_v。
  • 2 v x:将顶点 vv 的权重 WvW_v 修改为 Wv+xW_v + x。
  • 3 v:设顶点 vv 的颜色为 cc,输出所有可通过仅经过颜色为 cc 的顶点(包括顶点 vv 自身)从顶点 vv 到达的顶点的权重之和。

输入格式

The input is given from Standard Input in the following format, where queryi\mathrm{query}_i denotes the ii-th query:

NN QQ
W1W_1 W2W_2 …\dots WNW_N
C1C_1 C2C_2 …\dots CNC_N
a1a_1 b1b_1
a2a_2 b2b_2
⋮\vdots
aN−1a_{N-1} bN−1b_{N-1}
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

Each query is given in one of the following formats:

11 vv

22 vv xx

33 vv

输入从标准输入中按以下格式给出,其中 queryi\mathrm{query}_i 表示第 ii 个查询:

NN QQ
W1W_1 W2W_2 …\dots WNW_N
C1C_1 C2C_2 …\dots CNC_N
a1a_1 b1b_1
a2a_2 b2b_2
⋮\vdots
aN−1a_{N-1} bN−1b_{N-1}
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

每个查询以如下格式之一给出:

11 vv

22 vv xx

33 vv

输出格式

Let mm be the number of type-33 queries given. Output mm lines. The ii-th line should contain the answer for the ii-th type-33 query.

设给定的类型-3 查询数量为 mm。输出 mm 行,其中第 ii 行应包含第 ii 个类型-3 查询的答案。

输入输出样例

  • 输入#1

    5 9
    1 10 100 1000 10000
    0 0 0 0 0
    1 2
    2 3
    3 4
    2 5
    3 1
    1 2
    3 1
    3 2
    3 3
    1 3
    1 2
    2 1 1
    3 5

    输出#1

    11111
    1
    10
    1100
    10012
  • 输入#2

    10 25
    1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000
    0 1 0 0 0 1 0 0 0 0
    1 2
    1 3
    2 4
    4 5
    4 6
    2 7
    5 8
    8 9
    6 10
    3 4
    1 8
    2 6 100000
    3 3
    1 3
    1 7
    1 7
    1 7
    3 8
    2 1 1
    2 6 100000
    2 8 10000000
    1 5
    2 5 10000
    1 9
    2 7 1000000
    1 7
    2 10 1000000000
    1 9
    1 6
    1 9
    1 1
    3 7
    2 5 10000
    3 6

    输出#2

    110011000
    101
    10000000
    2000000
    2000301000

说明/提示

Sample 1 Explanation:
For example, for the first query, the set of vertices reachable from vertex 11 by traveling only through vertices of color 00 is {1,2,3,4,5}\lbrace 1,2,3,4,5 \rbrace.

Constraints

  • 1≤N≤3×1051 \leq N \leq 3 \times 10^5
  • 1≤Q≤2×1051 \leq Q \leq 2 \times 10^5
  • 1≤Wi≤1091 \leq W_i \leq 10^9
  • Ci∈{0,1}C_i \in \lbrace 0,1 \rbrace
  • 1≤ai<bi≤N1 \leq a_i \lt b_i \leq N
  • The input graph is a tree.
  • 1≤v≤N1 \leq v \leq N
  • 1≤x≤1091 \leq x \leq 10^9
  • All input values are integers.

样例 1 解释:
例如,对于第一个查询,仅通过颜色为 00 的顶点可达的、从顶点 11 出发的顶点集合为 {1,2,3,4,5}\lbrace 1,2,3,4,5 \rbrace。

限制条件

  • 1≤N≤3×1051 \leq N \leq 3 \times 10^5
  • 1≤Q≤2×1051 \leq Q \leq 2 \times 10^5
  • 1≤Wi≤1091 \leq W_i \leq 10^9
  • Ci∈{0,1}C_i \in \lbrace 0,1 \rbrace
  • 1≤ai<bi≤N1 \leq a_i \lt b_i \leq N
  • 输入图是一棵树。
  • 1≤v≤N1 \leq v \leq N
  • 1≤x≤1091 \leq x \leq 10^9
  • 所有输入值均为整数。

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

首页