CF1872E.Data Structures Fan

传统题 时间 2000 ms 内存 256 MiB 8 尝试 3 已通过 1 标签

Data Structures Fan

You are given an array of integers a1,a2,,ana_1, a_2, \ldots, a_n, as well as a binary string^{\dagger} ss consisting of nn characters.

Augustin is a big fan of data structures. Therefore, he asked you to implement a data structure that can answer qq queries. There are two types of queries:

  • "1 ll rr" (1lrn1\le l \le r \le n) — replace each character sis_i for lirl \le i \le r with its opposite. That is, replace all 0 with 1 and all 1 with 0.
  • "2 gg" (g{0,1}g \in \{0, 1\}) — calculate the value of the bitwise XOR of the numbers aia_i for all indices ii such that si=gs_i = g. Note that the XOR\operatorname{XOR} of an empty set of numbers is considered to be equal to 00.

Please help Augustin to answer all the queries!

For example, if n=4n = 4, a=[1,2,3,6]a = [1, 2, 3, 6], s=1001s = \texttt{1001}, consider the following series of queries:

  1. "2 00" — we are interested in the indices ii for which si=0s_i = \tt{0}, since s=1001s = \tt{1001}, these are the indices 22 and 33, so the answer to the query will be a2a3=23=1a_2 \oplus a_3 = 2 \oplus 3 = 1.
  2. "1 11 33" — we need to replace the characters s1,s2,s3s_1, s_2, s_3 with their opposites, so before the query s=1001s = \tt{1001}, and after the query: s=0111s = \tt{0111}.
  3. "2 11" — we are interested in the indices ii for which si=1s_i = \tt{1}, since s=0111s = \tt{0111}, these are the indices 22, 33, and 44, so the answer to the query will be $a_2 \oplus a_3 \oplus a_4 = 2 \oplus 3 \oplus 6 = 7$.
  4. "1 22 44" — s=0111s = \tt{0111} \to s=0000s = \tt{0000}.
  5. "2 11" — s=0000s = \tt{0000}, there are no indices with si=1s_i = \tt{1}, so since the XOR\operatorname{XOR} of an empty set of numbers is considered to be equal to 00, the answer to this query is 00.

^{\dagger} A binary string is a string containing only characters 0 or 1.

Input

The first line of the input contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases in the test.

The descriptions of the test cases follow.

The first line of each test case description contains an integer nn (1n1051 \le n \le 10^5) — the length of the array.

The second line of the test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9).

The third line of the test case contains the binary string ss of length nn.

The fourth line of the test case contains one integer qq (1q1051 \le q \le 10^5) — the number of queries.

The subsequent qq lines of the test case describe the queries. The first number of each query, tp{1,2}tp \in \{1, 2\}, characterizes the type of the query: if tp=1tp = 1, then 22 integers 1lrn1 \le l \le r \le n follow, meaning that the operation of type 11 should be performed with parameters l,rl, r, and if tp=2tp = 2, then one integer g{0,1}g \in \{0, 1\} follows, meaning that the operation of type 22 should be performed with parameter gg.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5, and also that the sum of qq over all test cases does not exceed 10510^5.

Output

For each test case, and for each query of type 22 in it, output the answer to the corresponding query.

Note

Let's analyze the first test case:

  1. "2 00" — we are interested in the indices ii for which si=0s_i = \tt{0}, since s=01000s = \tt{01000}, these are the indices 1,3,41, 3, 4, and 55, so the answer to the query will be $a_1 \oplus a_3 \oplus a_4 \oplus a_5 = 1 \oplus 3 \oplus 4 \oplus 5 = 3$.
  2. "2 11" — we are interested in the indices ii for which si=1s_i = \tt{1}, since s=01000s = \tt{01000}, the only suitable index is 22, so the answer to the query will be a2=2a_2 = 2.
  3. "1 22 44" — we need to replace the characters s2,s3,s4s_2, s_3, s_4 with their opposites, so before the query s=01000s = \tt{01000}, and after the query: s=00110s = \tt{00110}.
  4. "2 00" — we are interested in the indices ii for which si=0s_i = \tt{0}, since s=00110s = \tt{00110}, these are the indices 1,21, 2, and 55, so the answer to the query will be $a_1 \oplus a_2 \oplus a_5 = 1 \oplus 2 \oplus 5 = 6$.
  5. "2 11" — we are interested in the indices ii for which si=1s_i = \tt{1}, since s=00110s = \tt{00110}, these are the indices 33 and 44, so the answer to the query will be a3a4=34=7a_3 \oplus a_4 = 3 \oplus 4 = 7.
  6. "1 11 33" — s=00110s = \tt{00110} \to s=11010s = \tt{11010}.
  7. "2 11" — we are interested in the indices ii for which si=1s_i = \tt{1}, since s=11010s = \tt{11010}, these are the indices 1,21, 2, and 44, so the answer to the query will be $a_1 \oplus a_2 \oplus a_4 = 1 \oplus 2 \oplus 4 = 7$.

Samples

5
5
1 2 3 4 5
01000
7
2 0
2 1
1 2 4
2 0
2 1
1 1 3
2 1
6
12 12 14 14 5 5
001001
3
2 1
1 2 4
2 1
4
7 7 7 777
1111
3
2 0
1 2 3
2 0
2
1000000000 996179179
11
1
2 1
5
1 42 20 47 7
00011
5
1 3 4
1 1 1
1 3 4
1 2 4
2 0
3 2 6 7 7 
11 7 
0 0 
16430827 
47 

在线编程 IDE

建议全屏模式获得最佳体验