#P10926. Happybob's Magic (UBC001F)
Happybob's Magic (UBC001F)
Problem Description
Happybob is studying a row of lights in a game. There are lights in total, numbered from to . Happybob has two skills.
Skill 1 (press B to cast): Each time it is cast, all lights are toggled: on becomes off, and off becomes on.
Skill 2 (press D to cast) is stronger. Each time it is cast, suppose the set of indices of all lights that are on before casting is . Then, for all subsets (including the empty set) of , Happybob will turn on the light with index . Here is the size of set , and is the bitwise XOR of all elements in set . In particular, .
Now you are given a casting sequence consisting of B and D (with the meanings above), an initial light state sequence (version ) , and a variable . Happybob has queries, and each query can be one of the following:
1 v l r: Increase by . Starting from version , apply the casting operations through in order, store the result as version , and ask how many lights are on in version .2 v k: Ask whether the -th light in version is on. Output if it is on, otherwise output .3 v k: Suppose version was obtained from version by applying casting operations. Ask, among these casts, after how many casts the -th light is on (do not count the times when it was already on initially).
For the third type of query, and are defined as follows: if after some type 1 query we have , then is the value given in that query, and is the length of the operation sequence given in that query.
It is guaranteed that (for a type 1 query, this refers to before adding ; for a type 3 query, it is also guaranteed that .
Input Format
Line : three integers .
Line : integers .
Line : a string (1-indexed). For each integer with , if is B, it means Happybob casts skill 1 once; otherwise, he casts skill 2 once.
The next lines: each line contains or non-negative integers, representing a query.
Output Format
Output lines. The -th line contains one integer, representing the answer to the -th query.
3 10 6
0 1 0 1 0 1 0 0
BDBDBDDBBD
1 0 1 5
1 0 8 10
1 0 6 8
2 2 4
2 3 4
3 1 3
7
8
0
1
0
2
Hint
Sample Explanation
| Version ID | Light states |
|---|---|
For the last query, the states after each cast are as follows:
| Operation | Light states |
|---|---|
| Initial | |
B |
|
BD |
|
BDB |
|
BDBD |
|
BDBDB |
The 3rd light is turned on times.
Constraints
For of the testdata: , , , , . It is guaranteed that contains only characters B and D (it may contain no B or no D), and the length of is .
Translated by ChatGPT 5