问题2441--Broken Counter

2441: Broken Counter

时间限制: 60 Sec  内存限制: 128 MB
提交: 6  解决: 1
[提交] [状态] [讨论版] [命题人:]

题目描述

Bobo made a very long sequence of numbers (a1, a2, . . . , an) in ICPCCamp where ai = f(i) and
.
Now he wants to ask q questions where the i-th question is to compute the sum of ali , ali+1, . . . , ari . Unfortunately,
the only tool which Bobo can utilize is an old broken 4-bit counter. While trying to answer the i-th
question, Bobo will set the counter to 0, and add numbers to the counter in the order of ali , ali+1, . . . , ari .
As the counter is broken, adding the number a to a counter holding value x yields [(x⊕wi) + a] mod 16.
Note that “” stands for bitwise exclusive or (XOR).
Bobo would like to know the final result.
Special Note: The time limit is tight so that some optimization might be necessary. Try to solve the problem
as late as possible.

输入

The input contains zero or more test cases and is terminated by end-of-file. For each test case:
The first line contains five integers n, m, A, B, q. The i-th of the following q lines contains three integers li,
li and wi.
• 1 n 108
• 2 m 105
• 0 A,B,wi < 16
• 1 q 13
• 1 li ri n
• The number of test cases does not exceed 10.

样例输入

5 2 1 1 2
1 4 0
2 5 1

样例输出

2
15

来源/分类


[提交] [状态]