cf703D. Mishka and Interesting sum(树状数组)
2018-03-25 22:41
288 查看
题目
cf703d求区间内出现次数为偶数的数的的异或和
题解
要是求奇数就都会了是吧,它它它偏偏求偶数哎呦喂真是的我们知道一个数异或两次就相当于没有
所以..出现次数为偶数的异或和=区间所有数的异或和^区间内出现过的数的异或和
这样出现次数为奇数的就没了嘿嘿嘿真棒
区间内所有数的好求,那怎么求出现过的数的呢
记录每个数上一次出现的位置pos
然后…就..这样吧(表达能力有毒)
代码
#include <cstdio> #include <cmath> #include <algorithm> using namespace std; #define N 1000010 int a ,b ,n,m,l=0,r=0,sum ,ans ,t ,h ; struct node{int x,y,num;}c ; bool cmp(node x,node y){return x.y<y.y;} void add(int x,int y){ for(;x<=n;x+=x&-x) t[x]^=b[y]; } int query(int x){ int y=0;for(;x;x-=x&-x) y^=t[x]; return y; } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i],sum[i]=sum[i-1]^a[i]; sort(b+1,b+n+1);int nn=unique(b+1,b+n+1)-b-1; for(int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+nn+1,a[i])-b; scanf("%d",&m); for(int i=1;i<=m;i++) scanf("%d%d",&c[i].x,&c[i].y),c[i].num=i; sort(c+1,c+m+1,cmp);int j=0; for(int i=1;i<=n;i++){ if(h[a[i]]) add(h[a[i]],a[i]); add(i,a[i]);h[a[i]]=i; while(c[j+1].y==i){j++;ans[c[j].num]=query(c[j].x-1)^query(c[j].y)^sum[c[j].y]^sum[c[j].x-1]; } } for(int i=1;i<=m;i++) printf("%d\n",ans[i]); return 0; }
相关文章推荐
- codeforces CF703D Mishka and Interesting sum 树状数组
- 树状数组【CF703D】Mishka and Interesting sum
- Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum (离线树状数组+前缀xor)
- Codeforces 703D Mishka and Interesting sum 树状数组
- Codeforces Round #365 (Div. 2) Mishka and Interesting sum 树状数组
- codeforces 703D D. Mishka and Interesting sum(树状数组)
- Codeforces Round #365 (Div. 2) D - Mishka and Interesting sum(离线树状数组)
- Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum(离线树状数组)
- Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum(树状数组)
- CodeForces 703D Mishka and Interesting sum (树状数组 区间偶数异或)
- CodeForces 703D Mishka and Interesting sum (树状数组处理异或和)
- Codeforces 703D Mishka and Interesting sum (树状数组求区间内不同的数的异或和)
- CodeForces 703D Mishka and Interesting sum(树状数组 区间异或)
- Codeforces Round #365 (Div. 2)-D Mishka and Interesting sum(树状数组)
- D. Mishka and Interesting sum(树状数组 前缀异或和)
- Codeforces Round #365 (Div. 2) D.Mishka and Interesting sum (树状数组维护异或值) ★ ★
- Codeforces Round #365 (Div. 2) D Mishka and Interesting sum (离线树状数组)
- CodeForces703D Mishka and Interesting sum(树状数组)
- 【codeforces 703 D】【离线询问 树状数组 前驱思想 前缀异或和】D. Mishka and Interesting sum【 区间内出现次数偶数的数的异或和】
- codeforces 703D Mishka and Interesting sum (树状数组区间异或)