CF1872E.Data Structures Fan
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array of integers a1,a2,…,an , as well as a binary string † s consisting of n characters.
Augustin is a big fan of data structures. Therefore, he asked you to implement a data structure that can answer q queries. There are two types of queries:
- "1 l r " ( 1≤l≤r≤n ) — replace each character si for l≤i≤r with its opposite. That is, replace all 0 with 1 and all 1 with 0 .
- "2 g " ( g∈{0,1} ) — calculate the value of the bitwise XOR of the numbers ai for all indices i such that si=g . Note that the XOR of an empty set of numbers is considered to be equal to 0 .
Please help Augustin to answer all the queries!
For example, if n=4 , a=[1,2,3,6] , s=1001 , consider the following series of queries:
- "2 0 " — we are interested in the indices i for which si=0 , since s=1001 , these are the indices 2 and 3 , so the answer to the query will be a2⊕a3=2⊕3=1 .
- "1 1 3 " — we need to replace the characters s1,s2,s3 with their opposites, so before the query s=1001 , and after the query: s=0111 .
- "2 1 " — we are interested in the indices i for which si=1 , since s=0111 , these are the indices 2 , 3 , and 4 , so the answer to the query will be a2⊕a3⊕a4=2⊕3⊕6=7 .
- "1 2 4 " — s=0111 → s=0000 .
- "2 1 " — s=0000 , there are no indices with si=1 , so since the XOR of an empty set of numbers is considered to be equal to 0 , the answer to this query is 0 .
† A binary string is a string containing only characters 0 or 1 .
输入格式
The first line of the input contains one integer t ( 1≤t≤104 ) — 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 n ( 1≤n≤105 ) — the length of the array.
The second line of the test case contains n integers a1,a2,…,an ( 1≤ai≤109 ).
The third line of the test case contains the binary string s of length n .
The fourth line of the test case contains one integer q ( 1≤q≤105 ) — the number of queries.
The subsequent q lines of the test case describe the queries. The first number of each query, tp∈{1,2} , characterizes the type of the query: if tp=1 , then 2 integers 1≤l≤r≤n follow, meaning that the operation of type 1 should be performed with parameters l,r , and if tp=2 , then one integer g∈{0,1} follows, meaning that the operation of type 2 should be performed with parameter g .
It is guaranteed that the sum of n over all test cases does not exceed 105 , and also that the sum of q over all test cases does not exceed 105 .
输出格式
For each test case, and for each query of type 2 in it, output the answer to the corresponding query.
输入输出样例
输入#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:
- "2 0 " — we are interested in the indices i for which si=0 , since s=01000 , these are the indices 1,3,4 , and 5 , so the answer to the query will be a1⊕a3⊕a4⊕a5=1⊕3⊕4⊕5=3 .
- "2 1 " — we are interested in the indices i for which si=1 , since s=01000 , the only suitable index is 2 , so the answer to the query will be a2=2 .
- "1 2 4 " — we need to replace the characters s2,s3,s4 with their opposites, so before the query s=01000 , and after the query: s=00110 .
- "2 0 " — we are interested in the indices i for which si=0 , since s=00110 , these are the indices 1,2 , and 5 , so the answer to the query will be a1⊕a2⊕a5=1⊕2⊕5=6 .
- "2 1 " — we are interested in the indices i for which si=1 , since s=00110 , these are the indices 3 and 4 , so the answer to the query will be a3⊕a4=3⊕4=7 .
- "1 1 3 " — s=00110 → s=11010 .
- "2 1 " — we are interested in the indices i for which si=1 , since s=11010 , these are the indices 1,2 , and 4 , so the answer to the query will be a1⊕a2⊕a4=1⊕2⊕4=7 .