#P5280. [ZJOI2019] 线段树
[ZJOI2019] 线段树
Description
Jiutiao Kelian is a girl who likes data structures. Among common data structures, her favorite is the segment tree.
The core of a segment tree is lazy propagation. Below is pseudocode for a segment tree with lazy tags, where the array is the lazy tag:

Here, the function denotes the left child of , and denotes the right child of .
Now Kelian has a segment tree over , with index . All nodes in this segment tree have . Then Kelian performs operations. There are two types of operations:
-
: Suppose Kelian currently has segment trees. She will copy each segment tree into two copies (the array is copied as well). The segment tree originally indexed becomes two copied trees indexed and . After copying, she has segment trees in total. Then, she performs once on every segment tree whose index is odd.
-
: Kelian defines the weight of a segment tree as the number of nodes in it whose equals . She wants to know the sum of weights of all segment trees she currently has.
Input Format
The first line contains two integers , denoting the initial interval length and the number of operations.
Each of the next lines describes one operation. The input guarantees .
Output Format
For each query, output one integer per line representing the answer. The answer can be very large, so output it modulo .
5 5
2
1 1 3
2
1 3 5
2
0
1
6
Hint
The segment tree over is shown below:

At the first query, Kelian has one segment tree, and there are no marks on any node, so the answer is .
At the second query, Kelian has two segment trees. By their indices, their marked nodes are:
- Node is marked, so the weight is .
- No node is marked, so the weight is .
So the answer is .
At the third query, Kelian has four segment trees. By their indices, their marked nodes are:
- Nodes are marked, so the weight is .
- Node is marked, so the weight is .
- Nodes are marked, so the weight is .
- No node is marked, so the weight is .
So the answer is .
| Test Point | Other Constraints | ||
|---|---|---|---|
| None | |||
| ^ | ^ | ^ | |
| ^ | |||
| There is only one query | |||
| ^ | ^ | ||
| None | |||
| ^ | |||
For of the data, .
Translated by ChatGPT 5
京公网安备 11011102002149号