Distributive Property

시간 제한5초메모리 제한2048 MB

요약
집합의 원소를 넣고 빼는 갱신과 함께, 모든 원소 x에 대해 (x+t)의 XOR을 구하는 질의에 답한다.
난이도

어려움10점 중 9점

유형
비트 연산, 트라이, 누적 합
정답자
아직 제출이 없습니다

문제

You are given a set SS of nn distinct integers. You will also receive qq queries, each of one of the following two types:

  1. Query Type 1 (11 xx):

    • If xx is currently in the set SS, remove it.
    • Otherwise, add xx to the set.
  2. Query Type 2 (22 tt):

    • Print the cumulative bitwise XOR of (x+t)(x + t) over all x∈Sx \in S. Formally, print ⨁_x∈S(x+t)\displaystyle\bigoplus\_{x \in S} (x + t).

입력

The first line of the input contains two integers nn and qq (1≤n,q≤3⋅1051 \leq n,q \leq 3 \cdot 10^5) --- the initial size of the set and the number of queries, respectively.

The next line of the input will contain nn distinct integers x_1,x_2⋯x_nx\_1, x\_2 \cdots x\_n (0≤x_i<2200 \le x\_i < 2^{20}) --- the initial set.

The next qq lines of the input will describe the queries. Each of them will contain a query of the form 11 xx or 22 tt (0≤x,t<2200 \le x, t < 2^{20}), representing the query in the format described above.

It is guaranteed that there is at least one query of type 22.

출력

For each query of type 22, print the cumulative bitwise XOR of (x+t)(x+t) over all x∈Sx \in S.

힌트

In the sample case, at the time of the first type 22 query, we have S=1,6,15S = \\{1, 6, 15\\}. Since t=0t = 0 for this query, we print the value (1+0)⊕(6+0)⊕(15+0)=1⊕6⊕15=8(1 + 0) \oplus (6 + 0) \oplus (15 + 0) = 1 \oplus 6 \oplus 15 = 8 At the time of the second type 22 query, we have S=1,5,10,15S = \\{1, 5, 10, 15\\}. Since t=3t = 3 for this query, we print the value (1+3)⊕(5+3)⊕(10+3)⊕(15+3)=4⊕8⊕13⊕18=19(1 + 3) \oplus (5 + 3) \oplus (10 + 3) \oplus (15 + 3) = 4 \oplus 8 \oplus 13 \oplus 18 = 19

예제1

  1. 예제 1

    입력
    3 10
    1 6 15
    2 0
    1 5
    1 6
    1 10
    2 3
    2 12
    1 15
    2 7
    1 0
    2 7
    
    예상 출력
    8
    19
    17
    21
    18