Present

시간 제한3초메모리 제한1024 MB

요약
크기가 최대 400,000인 배열에서 모든 쌍의 합 a_i + a_j (i < j)를 구해 전부 XOR한 값을 계산한다.
난이도

보통10점 중 7점

유형
비트 연산, 정렬, 이분 탐색, 수학
정답자
아직 제출이 없습니다

문제

Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one --- xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute

\begin{align\*} (a\_1 + a\_2) \oplus (a\_1 + a\_3) \oplus \ldots \oplus (a\_1 + a\_n) \oplus \\\ \oplus (a\_2 + a\_3) \oplus \ldots \oplus (a\_2 + a\_n) \oplus \\\ \ldots \\\ \oplus (a\_{n-1} + a\_n) \\\ \end{align\*}

입력

The first line contains a single integer nn (2≤n≤400,0002 \leq n \leq 400\\,000) --- the number of integers in the array.

The second line contains integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (1≤a_i≤1071 \leq a\_i \leq 10^7).

출력

Print a single integer --- xor of all pairwise sums of integers in the given array.

힌트

In the first sample case there is only one sum 1+2=31 + 2 = 3.

In the second sample case there are three sums: 1+2=31 + 2 = 3, 1+3=41 + 3 = 4, 2+3=52 + 3 = 5. In binary they are represented as 011_2⊕100_2⊕101_2=010_2011\_2 \oplus 100\_2 \oplus 101\_2 = 010\_2, thus the answer is 2.

⊕\oplus is the bitwise xor operation. To define x⊕yx \oplus y, consider binary representations of integers xx and yy. We put the ii-th bit of the result to be 1 when exactly one of the ii-th bits of xx and yy is 1. Otherwise, the ii-th bit of the result is put to be 0. For example, 0101_2,⊕,0011_2=0110_20101\_2 \\, \oplus \\, 0011\_2 = 0110\_2.

예제2

  1. 예제 1

    입력
    2
    1 2
    
    예상 출력
    3
    
  2. 예제 2

    입력
    3
    1 2 3
    
    예상 출력
    2