CF1872E.Data Structures Fan

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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" (1≤l≤r≤n1\le l \le r \le n) — replace each character sis_i for l≤i≤rl \le i \le r with its opposite. That is, replace all 0\texttt{0} with 1\texttt{1} and all 1\texttt{1} with 0\texttt{0}.
  • "2 gg" (g∈0,1g \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 a2⊕a3=2⊕3=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 a2⊕a3⊕a4=2⊕3⊕6=7a_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\texttt{0} or 1\texttt{1}.

给你一个整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n,以及一个由 nn 个字符组成的二进制字符串†^{\dagger} ss。

奥古斯丁是一位数据结构爱好者。因此,他请你实现一种数据结构,以回答 qq 个查询。查询共分两类:

  • “1 ll rr”(其中 1≤l≤r≤n1\le l \le r \le n)——将所有满足 l≤i≤rl \le i \le r 的字符 sis_i 替换为其相反字符。即:将所有 0\texttt{0} 替换为 1\texttt{1},所有 1\texttt{1} 替换为 0\texttt{0}。
  • “2 gg”(其中 g∈{0,1}g \in \{0, 1\})——计算所有满足 si=gs_i = g 的下标 ii 对应的 aia_i 的按位异或值。注意:空集合的 XOR⁡\operatorname{XOR} 值定义为 00。

请帮助奥古斯丁回答所有查询!

例如,若 n=4n = 4,a=[1,2,3,6]a = [1, 2, 3, 6],s=1001s = \texttt{1001},考虑如下一系列查询:

  1. “2 00” —— 我们关注满足 si=0s_i = \tt{0} 的下标 ii;由于 s=1001s = \tt{1001},这些下标为 22 和 33,因此该查询的答案为 a2⊕a3=2⊕3=1a_2 \oplus a_3 = 2 \oplus 3 = 1。
  2. “1 11 33” —— 我们需将字符 s1,s2,s3s_1, s_2, s_3 替换为其相反字符;查询前 s=1001s = \tt{1001},查询后变为 s=0111s = \tt{0111}。
  3. “2 11” —— 我们关注满足 si=1s_i = \tt{1} 的下标 ii;由于 s=0111s = \tt{0111},这些下标为 22、33 和 44,因此该查询的答案为 a2⊕a3⊕a4=2⊕3⊕6=7a_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},不存在满足 si=1s_i = \tt{1} 的下标,因此根据空集合的 XOR⁡\operatorname{XOR} 值为 00 的约定,该查询的答案为 00。

†^{\dagger} 二进制字符串是指仅包含字符 0\texttt{0} 或 1\texttt{1} 的字符串。

输入格式

The first line of the input contains one integer tt (1≤t≤1041 \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 (1≤n≤1051 \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 (1≤ai≤1091 \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 (1≤q≤1051 \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,2tp \in {1, 2}, characterizes the type of the query: if tp=1tp = 1, then 22 integers 1≤l≤r≤n1 \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,1g \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.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 表示数组的长度。

测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)。

测试用例的第三行包含一个长度为 nn 的二进制字符串 ss。

测试用例的第四行包含一个整数 qq(1≤q≤1051 \le q \le 10^5)—— 表示查询的数量。

接下来的 qq 行描述了该测试用例中的各个查询。每个查询的第一项为数字 tp∈{1,2}tp \in \{1, 2\},用于表示查询类型:若 tp=1tp = 1,则其后跟随两个整数 1≤l≤r≤n1 \le l \le r \le n,表示需以参数 l,rl, r 执行类型 11 的操作;若 tp=2tp = 2,则其后跟随一个整数 g∈{0,1}g \in \{0, 1\},表示需以参数 gg 执行类型 22 的操作。

保证所有测试用例的 nn 之和不超过 10510^5,且所有测试用例的 qq 之和也不超过 10510^5。

输出格式

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

对于每个测试用例,以及其中每个类型为 22 的查询,输出对应查询的答案。

输入输出样例

  • 输入#1

    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

    输出#1

    3 2 6 7 7 
    11 7 
    0 0 
    16430827 
    47

说明/提示

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 a1⊕a3⊕a4⊕a5=1⊕3⊕4⊕5=3a_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 a1⊕a2⊕a5=1⊕2⊕5=6a_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 a3⊕a4=3⊕4=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 a1⊕a2⊕a4=1⊕2⊕4=7a_1 \oplus a_2 \oplus a_4 = 1 \oplus 2 \oplus 4 = 7.

我们来分析第一个测试用例:

  1. “2 00” — 我们关注满足 si=0s_i = \tt{0} 的下标 ii;由于 s=01000s = \tt{01000},这些下标为 1,3,41, 3, 4 和 55,因此该查询的答案为 a1⊕a3⊕a4⊕a5=1⊕3⊕4⊕5=3a_1 \oplus a_3 \oplus a_4 \oplus a_5 = 1 \oplus 3 \oplus 4 \oplus 5 = 3。
  2. “2 11” — 我们关注满足 si=1s_i = \tt{1} 的下标 ii;由于 s=01000s = \tt{01000},唯一满足条件的下标是 22,因此该查询的答案为 a2=2a_2 = 2。
  3. “1 22 44” — 我们需要将字符 s2,s3,s4s_2, s_3, s_4 替换为其相反字符;查询前 s=01000s = \tt{01000},查询后变为 s=00110s = \tt{00110}。
  4. “2 00” — 我们关注满足 si=0s_i = \tt{0} 的下标 ii;由于 s=00110s = \tt{00110},这些下标为 1,21, 2 和 55,因此该查询的答案为 a1⊕a2⊕a5=1⊕2⊕5=6a_1 \oplus a_2 \oplus a_5 = 1 \oplus 2 \oplus 5 = 6。
  5. “2 11” — 我们关注满足 si=1s_i = \tt{1} 的下标 ii;由于 s=00110s = \tt{00110},这些下标为 33 和 44,因此该查询的答案为 a3⊕a4=3⊕4=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” — 我们关注满足 si=1s_i = \tt{1} 的下标 ii;由于 s=11010s = \tt{11010},这些下标为 1,21, 2 和 44,因此该查询的答案为 a1⊕a2⊕a4=1⊕2⊕4=7a_1 \oplus a_2 \oplus a_4 = 1 \oplus 2 \oplus 4 = 7。

输入解题思路,AI测评打分。不知道怎么写?

首页