#P10016. [集训队互测 2023] 虹
[集训队互测 2023] 虹
Problem Description
You are given a tree with nodes.
- A set of nodes is called connected if and only if for all , every node on the simple path from to is also in .
- A set of nodes is called a rainbow of if and only if is connected and contains all nodes in .
- A set of nodes is called the minimum rainbow of if and only if has the smallest size among all rainbows of . It can be proven that is unique.
Each node has a weight. The weight of node is . Initially, all node weights are . Also, you are given a sequence .
You are given commands. Each command is one of the following two types:
1 l r: Let be the minimum rainbow of . For all , increase by .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 .
The second line contains non-negative integers, representing in order.
The next lines each contain two positive integers , describing an edge in the tree between and .
The last lines each contain or 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: . All commands satisfy . It is guaranteed that in the first type of commands are generated randomly. The random generation method is as follows:
- Randomly generate uniformly in .
- Randomly generate uniformly in .
- If , swap and .
Constraints
| Subtask ID | Score | Special Properties | Dependencies | ||
|---|---|---|---|---|---|
| None | None | ||||
| A, B | |||||
| A | Depends on Subtask | ||||
| None | Depends on Subtasks | ||||
| Depends on Subtasks | |||||
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 .
Translated by ChatGPT 5