### Codeforces 703D Mishka and Interesting sum（离线 + 树状数组）

`#include <bits/stdc++.h>using namespace std;#define rep(i, a, b)	for (int i(a); i <= (b); ++i)#define dec(i, a, b)	for (int i(a); i >= (b); --i)const int N = 1e6 + 10;struct node{	int l, r, id;	friend bool operator < (const node &a, const node &b){		return a.l == b.l ? a.r < b.r : a.l < b.l;	}} q[N];int a[N], c[N], nxt[N];int n, m;int ans[N], s[N];int l;unordered_map <int, int> mp;int update(int x, int val){	for (; x <= n; x += x & -x) c[x] ^= val;}int query(int x){	int ret = 0;	for (; x; x -= x & -x) ret ^= c[x];	return ret;}int undo(int x){	update(x, a[x]);	if (nxt[x]) update(nxt[x], a[nxt[x]]);}int main(){	scanf("%d", &n);	rep(i, 1, n) scanf("%d", a + i);	rep(i, 1, n) s[i] = s[i - 1] ^ a[i];	rep(i, 1, n){		if (mp.count(a[i])) continue;		else{			mp[a[i]] = 1;			update(i, a[i]);		}	}	mp.clear();	dec(i, n, 1){		nxt[i] = (mp.count(a[i])) ? mp[a[i]] : 0;		mp[a[i]]  = i;	}	scanf("%d", &m);	rep(i, 1, m){		scanf("%d%d", &q[i].l, &q[i].r);		q[i].id = i;	}	sort(q + 1, q + m + 1);	l = 1;	rep(i, 1, m){		while (l < q[i].l){			undo(l);			++l;		}		ans[q[i].id] = query(q[i].r) ^ s[q[i].r] ^ s[q[i].l - 1];	}	rep(i, 1, m) printf("%d\n", ans[i]);			return 0;}`