#P10016. [集训队互测 2023] 虹

    ID: 11345 远端评测题 4000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>集训队互测2023数论深度优先搜索 DFS最近公共祖先 LCA分块位运算

[集训队互测 2023] 虹

Problem Description

You are given a tree with nn nodes.

  • A set of nodes SS is called connected if and only if for all u,vSu, v \in S, every node on the simple path from uu to vv is also in SS.
  • A set of nodes SS is called a rainbow of [l,r][l, r] if and only if SS is connected and SS contains all nodes in [l,r][l, r].
  • A set of nodes S0S_0 is called the minimum rainbow of [l,r][l, r] if and only if S0S_0 has the smallest size among all rainbows of [l,r][l, r]. It can be proven that S0S_0 is unique.

Each node has a weight. The weight of node uu is wuw_u. Initially, all node weights are 00. Also, you are given a sequence {z1,z2,,zn}\{z_1, z_2, \cdots, z_n\}.

You are given qq commands. Each command is one of the following two types:

  • 1 l r: Let S0S_0 be the minimum rainbow of [l,r][l, r]. For all uS0u \in S_0, increase wuw_u by 11.
  • 2 l r u: Compute $\left(\sum_{i=l}^r 19901991^{z_{\gcd(i,u)} w_i} \right) \bmod {20242024}$.

Input Format

The first line contains two positive integers n,qn, q.

The second line contains nn non-negative integers, representing z1,z2,,znz_1, z_2, \cdots, z_n in order.

The next n1n - 1 lines each contain two positive integers u,vu, v, describing an edge in the tree between uu and vv.

The last qq lines each contain 33 or 44 positive integers, describing a command.

Note: Each line in the input file ends with \r. Please filter it out by yourself.

Output Format

For each query (i.e. each command of the second type), output the answer.

5 4
1 0 0 0 1
1 2
1 3
3 4
3 5
1 2 3
2 1 3 3
1 4 5
2 3 5 3
19561959
19561959

Hint

This problem uses bundled testdata.

For all testdata, it is guaranteed that: 1n,q8×104,0zi1091 \le n, q \le 8 \times 10^4, 0 \le z_i \le 10^9. All commands satisfy 1lrn,1un1 \le l \le r \le n, 1 \le u \le n. It is guaranteed that (l,r)(l, r) in the first type of commands are generated randomly. The random generation method is as follows:

  • Randomly generate ll uniformly in [1,n]Z[1, n] \cap \mathrm{Z}.
  • Randomly generate rr uniformly in [1,n]Z[1, n] \cap \mathrm{Z}.
  • If l>rl > r, swap ll and rr.

Constraints

Subtask ID Score nn \le qq \le Special Properties Dependencies
11 1010 10310^3 None None
22 2020 6553665536 A, B
33 A Depends on Subtask 22
44 3030 None Depends on Subtasks 1,2,31, 2, 3
55 2020 8000080000 Depends on Subtasks 1,2,3,41, 2, 3, 4

Special Property A: It is guaranteed that all commands of the second type appear after all commands of the first type.

Special Property B: It is guaranteed that the number of commands of the second type is 20\le 20.

Translated by ChatGPT 5