luogu#P7982. [JRKSJ R3] 琴琴的树
[JRKSJ R3] 琴琴的树
Problem Description
Qinqin has a binary tree that satisfies:
- The tree has infinitely many nodes.
- Each node has an index and a weight. Initially, the weight of every node is .
- The root node has index .
- If a node has index , then its left and right children have indices and , respectively.
Qinqin will perform a total of operations on the tree. Each operation is one of the following:
- Add to the weight of every node in the subtree rooted at the node with index .
- Query the sum of weights of all nodes on the path from the node with index to the node with index in the tree. The answer is taken modulo .
However, Qinqin will not directly give and . Instead, she gives a sequence of length . Each time she needs to give or , she provides an interval or . The number is the value of this interval interpreted as a binary number.
Input Format
The first line contains two integers .
The second line contains a string of length representing . It is guaranteed that the string contains only 0 and 1.
The next lines each contain an operation type, followed by the operation parameters. The formats are:
Output Format
For each operation of type , output one integer per line representing the answer.
5 5
01010
1 4 5 5
2 1 3 2 5
1 2 3 3
2 1 5 1 2
2 3 4 4 5
15
24
8
Hint
Sample Explanation
The first four levels of the tree are shown in the figure:

Operation 1: Add to the weights of all nodes in the subtree rooted at .
Operation 2: Query the sum of weights on the path .
Operation 3: Add to the weights of all nodes in the subtree rooted at .
Operation 4: Query the sum of weights on the path .
Operation 5: Query the sum of weights on the path .
Constraints
This problem uses bundled testdata.
| Score | |||
|---|---|---|---|
For of the data, , , , , and it is guaranteed that .
Translated by ChatGPT 5