#P3688. [ZJOI2017] 树状数组
[ZJOI2017] 树状数组
Description
On a dark night, Kurousagi Kotori tossed and turned in bed. Unable to sleep, she remembered a tragic OI contest experience years ago. It was a basic Binary Indexed Tree problem.
Given an array of length , initially all , perform operations of two types:
- : set to .
- : ask for .
Although Kotori was quite simple back then, she still noticed that this problem could be solved using a Binary Indexed Tree. When she was very young, she wrote the following algorithm:

Here denotes the lowest nonzero binary bit of number , e.g., . For the first type of operation she calls , and for the second type the answer is .
If you are familiar with Binary Indexed Trees, it is not hard to see that Kotori wrote it incorrectly: the direction in which changes in and is reversed. Therefore, this program spectacularly got a score of in the final test.
Strangely, at that time, this program passed the large sample test provided by the problem setter—this is also why Kotori did not conduct stress testing.
Now, Kotori wants to compute the probability that this program answers each query correctly, so she can once again feel how “fei” she was. However, many years have passed, and even Kotori cannot fully remember the large sample. Fortunately, she recalls most of it; the only thing she forgot is the value of for each type 1 operation, so she assumes that is chosen uniformly at random from the range for that operation.
Specifically, Kotori gives an array of length , initially , and then performs operations:
- : uniformly at random pick an in the interval and execute .
- : ask for the probability that executing yields the correct result.
Input Format
The first line contains two integers .
Each of the next lines describes one operation in the format specified above.
Output Format
For each query, output one integer representing the answer. If the simplified fraction of the answer is , you only need to output the value of (that is, output the answer modulo ).
5 5
1 3 3
2 3 5
2 4 5
1 1 3
2 2 5
1
0
665496236
Hint
-
Sample Explanation:
After performing , the array becomes . Therefore, the program’s answers for the first two queries are both . Hence, the first query is certainly correct, and the second query is certainly incorrect.
-
Constraints:
- Test point 1: , , no additional constraints.
- Test point 2: , , no additional constraints.
- Test point 3: , , no additional constraints.
- Test point 4: , , no additional constraints.
- Test point 5: , , no additional constraints.
- Test point 6: , , all queries occur after updates.
- Test point 7: , , all queries occur after updates.
- Test point 8: , , no additional constraints.
- Test point 9: , , no additional constraints.
- Test point 10: , , no additional constraints.
For of the testdata, it is guaranteed that .
Update: 2018/05/13 @larryzhong provided 5 stronger testdata sets.
Translated by ChatGPT 5
京公网安备 11011102002149号