codeforces 703D 树状数组 + 离线处理 + 离散化
来源:互联网 发布:mac上大型游戏 编辑:程序博客网 时间:2024/05/22 04:36
题意:给你m个操作,每个操作求区间[l,r]中偶数个元素的异或值。
分析:根据异或的性质,偶数个的异或为0,所以我们考虑再一次元素本身,因此,偶数变成奇数,奇数变成偶数。
具体详见代码:
#include<bits/stdc++.h>using namespace std;const int maxn = 1e6 +20;struct node{int l,r,id;bool operator < (const node & a){return r < a.r;}}q[maxn];int n , A[maxn],B[maxn],sum[maxn],ans[maxn],Map[maxn];struct BIT{int bit[maxn];void add(int x,int v){while(x<=n){bit[x] ^= v;x += x&-x;}}int sum(int x){int res = 0;while(x){res ^= bit[x];x -= x&-x;}return res;}}bit;int main(void){cin>>n;for(int i = 1;i <= n;i++){scanf("%d",&A[i]);sum[i] = sum[i-1] ^ A[i];B[i] = A[i];}sort(B + 1,B + n + 1);int x = unique(B + 1,B + n + 1) - B - 1;for(int i = 1;i <= n; i ++){A[i] = lower_bound(B + 1,B + x + 1,A[i]) - B;}int m,a,b,pos = 0;cin>>m;for(int i = 1;i <= m;i ++){scanf("%d%d",&q[i].l,&q[i].r);q[i].id = i;} sort(q+1,q+m+1);for(int i = 1;i <= m ; i ++){while(pos < q[i].r){pos++;if(Map[A[pos]]) bit.add(Map[A[pos]],B[A[pos]]);bit.add(pos,B[A[pos]]);Map[A[pos]] = pos;}ans[q[i].id] = sum[q[i].r] ^ sum[q[i].l-1] ^ bit.sum(q[i].r) ^ bit.sum(q[i].l-1);}for(int i = 1;i <= m; i++){printf("%d\n",ans[i]);} }
0 0
- codeforces 703D 树状数组 + 离线处理 + 离散化
- codeforces 703D(树状数组+离线处理)
- D - Data Mining-Gym 100496D-离线处理+树状数组+离散化
- Codeforces 652D Nested Segments 树状数组离线处理
- Codeforces 527D Clique Problem (dp+树状数组+离散化)
- Educational Codeforces Round 10D 离散化+树状数组
- Codeforces 652D Nested Segments 【树状数组 + 离散化】
- CodeForces 652D Nested Segments(树状数组+离散化)
- CodeForces 652D Nested Segments(离散化,树状数组)
- 【Codeforces 652 D Nested Segments】+ 树状数组 + 离散化
- Codeforces 652D Nested Segments【离散化+思维+树状数组】
- Nested Segments codeforces 652D 树状数组 +离散化
- CodeForces 652D Nested Segments(树状数组 离散化)
- Nested Segments CodeForces 652D 树状数组+离散化
- HDU3333 离线离散化树状数组
- Codeforces 538F A Heap of Heaps 离线+树状数组+离散化
- HDU 4358 Boring counting(树的遍历+树状数组+离散化+离线处理)
- HDU 4417 —— Super Mario(树状数组,离散化,离线处理)
- JavaScript中valueOf函数与toString方法重写优先级问题
- 超融合架构与容器超融合
- request.getParameterValues 与 request.getParameter 的区别
- Zookeeper的功能以及工作原理
- 集合的并
- codeforces 703D 树状数组 + 离线处理 + 离散化
- javascript面试题(9)
- 浙大PAT甲级 1030
- 自己写的一个扑克牌比较点数的小游戏
- 2016/08/20 接口练习题(1)
- APP引导页的集成
- 详细介绍如何向github库里上传自己的项目
- Android 仿微信联系人Demo(自定义View,Viewgroup)
- 谈程序员的一些缺点