Codeforces Round #365 (Div. 2) D.mishka and interesting sum tree array + offline

Source: Internet
Author: User

D. Mishka and interesting sumtime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard Inputoutputstan Dard output

Little Mishka enjoys programming. Since her birthday had just passed, she friends decided to present she with array of non-negative integers a C2>1, a2, ..., an of n elements!

Mishka loved the array and she instantly decided to determine it beauty value, but she is too little and can ' t process la rge arrays. Right because of this she invited you to visit her and asked to process m queries.

Each query was processed in the following:

  1. Integers l and R (1≤ lrn) are specified-bounds of Qu ery segment.
  2. integers, presented in array segment [l, R] (in sequence of integers al , al + 1, ..., aR) even number of times, is written down .
  3. Xor-sum of written down integers was calculated, and this value was the answer for a query. Formally, if integers written down with point 2 is x1, x2, ..., xk, the N Mishka wants to know the value, Where-operator of exclusive bitwise OR.

Since only the little bears know the definition of an array beauty, all your be to does is to answer each of the queries presented.

Input

The first line of the input contains a single integer n (1≤ n ≤1)-the number of Ele ments in the array.

The second line of the input contains n integers a1, a2, ..., a n ( 1≤ ai ≤109)-array elements.

The third line of the input contains single integer m (1≤ m ≤1)-the number of Queries.

Each of the next m lines describes corresponding query by a pair of integers l and r ( 1≤ lrn)-the bounds of query segment.

Output

Print m non-negative integers-the answers for the queries of the order they appear in the input.

Examplesinput
3
3 7 8
1
1 3
Output
0
Input
7
1 2 1 3 3 2 3
5
4 7
4 5
1 3
1 7
1 5
Output
0
3
1
3
2
Note

In the second sample:

There is no integers in the segment of the first query, presented even number of times in the segment-the answer is 0.

In the second query there are only integer 3 are presented even number of times-the answer is 3.

In the third query only integer 1 is written down-the answer is 1.

The fourth query all array elements is considered. Only 1 and 2 is presented there even number of times. The answer is.

In the fifth query 1 and 3 is written down. The answer is.

Idea: The use of off-line to find each interval of different numbers of XOR, and then the interval of the XOR, the interval of the XOR and the interval of the odd number of XOR;

The xor of the interval odd or and = = intervals with different numbers of interval xor and difference or interval;

#include <bits/stdc++.h>using namespacestd;#definell Long Long#defineESP 1E-10Const intn=1e6+Ten, m=1e6+Ten, mod=1e9+7, inf=1e9+Ten;struct  is{    intL,r; intPOS;} A[n];intB[n];intAns[n];map<int,int>Last ;intcmp isX isy) {    if(x.r!=Y.R)returnx.r<Y.R; returnx.l<Y.L;}intTreeunq[n];intTree[n];intLowbit (intx) {    returnx&-x;}intUpdateintXintChangeintNint*tree) {     while(x<=N) {tree[x]^=Change ; X+=lowbit (x); }}intQueryintXint*tree) {    intsum=0;  while(x) {sum^=Tree[x]; X-=lowbit (x); }    returnsum;}intMain () {intx,y,z,i,t;  while(~SCANF ("%d",&x) {memset (tree,0,sizeof(tree)); memset (TREEUNQ,0,sizeof(TREEUNQ));  for(i=1; i<=x;i++) {scanf ("%d",&B[i]); Tree[i]=B[i]; Y=lowbit (i);  for(t=1; t<y;t++) Tree[i]^=b[i-y+T]; } scanf ("%d",&y);  for(i=1; i<=y;i++) scanf ("%d%d", &AMP;A[I].L,&AMP;A[I].R), a[i].pos=i; Sort (a+1, a+y+1, CMP); intst=1;  for(i=1; i<=y;i++)        {             while(st<=A[I].R) {                if(last[b[st]]!=0) update (LAST[B[ST]],B[ST],X,TREEUNQ); LAST[B[ST]]=St;                Update (ST,B[ST],X,TREEUNQ); St++; } Ans[a[i].pos]=query (A[i].r,tree) ^query (a[i].l-1, tree) ^query (A[I].R,TREEUNQ) ^query (a[i].l-1, TREEUNQ); }         for(i=1; i<=y;i++) printf ("%d\n", Ans[i]); }    return 0;}

Codeforces Round #365 (Div. 2) D.mishka and interesting sum tree array + offline

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.