# Codeforces 703D 树状数组

Codeforces 703D

    #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
const int MAXN = 1e6 + 5;
int dp[MAXN], n;
int lowbit(int x){return x & -x;}
{
while(u <= n)
dp[u] ^= v,
u += lowbit(u);
}
int query(int u)
{
int res = 0;
while(u > 0) {
res ^= dp[u];
u -= lowbit(u);
}
return res;
}
struct Query
{
int l, r, id;
Query(){}
Query(int _l, int _r, int _id): l(_l), r(_r), id(_id){}
}que[MAXN];
bool cmp(Query q1, Query q2){return q1.r < q2.r;}
int a[MAXN];
int query(int o, int L, int R, int l, int r)
{
if(L >= l && R <= r) return dp[o];
else {
int res = 0;
int mid = (L + R) >> 1;
if(mid >= l) res ^= query(o << 1, L, mid, l, r);
if(mid < r) res ^= query((o << 1) | 1, mid + 1, R, l, r);
return res;
}
}
int ans[MAXN], sum[MAXN];
map<int,int>vis;
int main()
{
while(scanf("%d", &n) != EOF) {
for(int i = 1 ; i <= n ; i++) scanf("%d", &a[i]);
for(int i = 1 ; i <= n ; i++) sum[i] = sum[i - 1] ^ a[i];
int q; scanf("%d", &q);
for(int i = 0 ; i < q ; i++) {
scanf("%d%d", &que[i].l, &que[i].r);
que[i].id = i;
}
vis.clear();
int r = 0, l = 1;
sort(que, que + q, cmp);
for(int i = 0 ; i < q ; i++) {
while(r < que[i].r) {
r++;
if(vis[a[r]] == 0) vis[a[r]] = r;
else {
int last = vis[a[r]];
}