#P10926. Happybob's Magic (UBC001F)

Happybob's Magic (UBC001F)

Problem Description

Happybob is studying a row of lights in a game. There are 2n2^n lights in total, numbered from 00 to 2n12^n-1. 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 XX. Then, for all 2X2^{|X|} subsets (including the empty set) YY of XX, Happybob will turn on the light with index (Y)\bigoplus(Y). Here X|X| is the size of set XX, and (Y)\bigoplus(Y) is the bitwise XOR of all elements in set YY. In particular, ()=0\bigoplus(\varnothing) = 0.

Now you are given a casting sequence SS consisting of B and D (S=m)(|S|=m) (with the meanings above), an initial light state sequence (version 00) a0,a1,,a2n1a_0,a_1,\cdots,a_{2^n-1}, and a variable vid=0vid=0. Happybob has qq queries, and each query can be one of the following:

  1. 1 v l r: Increase vidvid by 11. Starting from version vv, apply the casting operations SlS_l through SrS_r in order, store the result as version vidvid, and ask how many lights are on in version vidvid.
  2. 2 v k: Ask whether the kk-th light in version vv is on. Output 11 if it is on, otherwise output 00.
  3. 3 v k: Suppose version vv was obtained from version vv' by applying tt casting operations. Ask, among these casts, after how many casts the kk-th light is on (do not count the times when it was already on initially).

For the third type of query, vv' and tt are defined as follows: if after some type 1 query we have vid=vvid = v, then vv' is the value vv given in that query, and tt is the length of the operation sequence SlrS_{l\cdots r} given in that query.

It is guaranteed that 0vvid0\le v\le vid (for a type 1 query, this refers to vidvid before adding 11; for a type 3 query, it is also guaranteed that v>0v>0.

Input Format

Line 11: three integers n,m,qn,m,q.

Line 22: 2n2^n integers a0,a1,,a2n1a_0,a_1,\cdots,a_{2^n-1}.

Line 33: a string SS (1-indexed). For each integer ii with 1im1\le i\le m, if SiS_i is B, it means Happybob casts skill 1 once; otherwise, he casts skill 2 once.

The next qq lines: each line contains 33 or 44 non-negative integers, representing a query.

Output Format

Output qq lines. The ii-th line contains one integer, representing the answer to the ii-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
00 0101010001010100
11 0111111101111111
22 1111111111111111
33 0000000000000000

For the last query, the states after each cast are as follows:

Operation Light states
Initial 0101010001010100
B 1010101110101011
BD 11111111111\red11111
BDB 0000000000000000
BDBD 1000000010000000
BDBDB 01111111011\red11111

The 3rd light is turned on 22 times.

Constraints

For 100%100\% of the testdata: 1n181\le n\le 18, 1q2×1051\le q\le 2\times 10^5, ai{0,1}a_i\in\{0, 1\}, 1lrm2×1051\le l\le r\le m\le 2\times 10^5, 0k<2n0\le k<2^n. It is guaranteed that SS contains only characters B and D (it may contain no B or no D), and the length of SS is mm.

Translated by ChatGPT 5