CF1044D.Deduction Queries
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is an array a of 230 integers, indexed from 0 to 230−1 . Initially, you know that 0≤ai<230 ( 0≤i<230 ), but you do not know any of the values. Your task is to process queries of two types:
- 1 l r x: You are informed that the bitwise xor of the subarray [l,r] (ends inclusive) is equal to x . That is, al⊕al+1⊕…⊕ar−1⊕ar=x , where ⊕ is the bitwise xor operator. In some cases, the received update contradicts past updates. In this case, you should ignore the contradicting update (the current update).
- 2 l r: You are asked to output the bitwise xor of the subarray [l,r] (ends inclusive). If it is still impossible to know this value, considering all past updates, then output −1 .
Note that the queries are encoded. That is, you need to write an online solution.
输入格式
The first line contains a single integer q ( 1≤q≤2⋅105 ) — the number of queries.
Each of the next q lines describes a query. It contains one integer t ( 1≤t≤2 ) — the type of query.
The given queries will be encoded in the following way: let last be the answer to the last query of the second type that you have answered (initially, last=0 ). If the last answer was −1 , set last=1 .
-
If t=1 , three integers follow, l′ , r′ , and x′ ( 0≤l′,r′,x′<230 ), meaning that you got an update. First, do the following: l=l′⊕last , r=r′⊕last , x=x′⊕last and, if l>r , swap l and r .
This means you got an update that the bitwise xor of the subarray [l,r] is equal to x (notice that you need to ignore updates that contradict previous updates).
-
If t=2 , two integers follow, l′ and r′ ( 0≤l′,r′<230 ), meaning that you got a query. First, do the following: l=l′⊕last , r=r′⊕last and, if l>r , swap l and r .
For the given query, you need to print the bitwise xor of the subarray [l,r] . If it is impossible to know, print −1 . Don't forget to change the value of last .
It is guaranteed there will be at least one query of the second type.
输出格式
After every query of the second type, output the bitwise xor of the given subarray or −1 if it is still impossible to know.
输入输出样例
输入#1
12 2 1 2 2 1 1073741822 1 0 3 4 2 0 0 2 3 3 2 0 3 1 6 7 3 2 4 4 1 0 2 1 2 0 0 2 4 4 2 0 0
输出#1
-1 -1 -1 -1 5 -1 6 3 5
输入#2
4 1 5 5 9 1 6 6 5 1 6 5 10 2 6 5
输出#2
12
说明/提示
In the first example, the real queries (without being encoded) are:
-
12
-
2 1 2
-
2 0 1073741823
-
1 1 2 5
-
2 1 1
-
2 2 2
-
2 1 2
-
1 2 3 6
-
2 1 1
-
1 1 3 0
-
2 1 1
-
2 2 2
-
2 3 3
-
The answers for the first two queries are −1 because we don't have any such information on the array initially.
-
The first update tells us a1⊕a2=5 . Note that we still can't be certain about the values a1 or a2 independently (for example, it could be that a1=1,a2=4 , and also a1=3,a2=6 ).
-
After we receive all three updates, we have enough information to deduce a1,a2,a3 independently.
In the second example, notice that after the first two updates we already know that a5⊕a6=12 , so the third update is contradicting, and we ignore it.