树状数组扩展(异或求和)
来源:互联网 发布:网络兼职都是干什么的 编辑:程序博客网 时间:2024/04/30 03:29
题目:逃票的chanming
题意:操作0: 读入p,q,v,并且a[p] ^= v, a[p + 1] ^= v, .. ,a[q] ^= v;操作1: 读入p,q,输出s = a[p] ^ a[p + 1] ^ a[p + 2]..^a[q]的结果;
思路:
代码:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <iostream>#include <algorithm>#include <queue>#include <stack>#include <vector>#include <set>#include <string>using namespace std;#define For(i,a) for(i=0;i<a;i++)#define Foru(i,a,b) for(i=a;i<=b;i++)#define Ford(i,a,b) for(i=a;i>=b;i--)#define clr(ar,vel) memset(ar,vel,sizeof(ar))#define PB push_back#define maxint 0x7fffffff#define maxn 500010template <int SZ>class BIT{ long long c[SZ+10];public : void clear(){clr(c,0);} long long getsum(int x){ long long s=0; while(x>0) s^=c[x], x-=x&-x; return s; } void update(int x, int n){ while(x<=SZ) c[x]^=n,x+=x&-x; }};BIT <maxn> sum, sumi;int main(){int n, m;int act, s, t, v;//for(int i = 0; i < 10; i ++) cout << (i&1) << endl;scanf("%d%d",&n,&m);for(int i = 0; i < m; i ++) {scanf("%d%d%d",&act,&s,&t);if( !act ) {scanf("%d",&v);sum.update(s,v);sumi.update(s,v*(s&1));sum.update(t+1,v);sumi.update(t+1,v*((t+1)&1));}else{//cout << sum.getsum(t) << ' ' << sumi.getsum(t) << endl; int w = ((t+1)&1)*sum.getsum(t)^sumi.getsum(t);//cout << w << endl;w ^= (s&1)*sum.getsum(s-1)^sumi.getsum(s-1);printf("%d\n",w);}}return 0;}
0 0
- 树状数组扩展(异或求和)
- NOJ——1669xor的难题(树状数组的异或求和)
- 树状数组入门(求和)
- 树状数组--区间求和
- 树状数组,区间求和
- 树状数组+异或运算
- 51Nod 1081 子段求和(数组/树状数组)
- 树状数组二维扩展
- 树状数组扩展
- NYOJ 108 士兵杀敌 (一) (树状数组&区间求和)
- hdu 1556 树状数组(区间更新,单点求和)
- poj 1990 MooFest(转化成树状数组求和)
- HDU 1541 Stars (树状数组 区间求和)
- 51nod:1081 子段求和(树状数组)
- hdu1166(树状数组,点修改,区间求和)
- poj1195(二维树状数组,点修改,区间求和)
- CF301D(树状数组,离线统计,区间求和)
- 敌兵布阵------树状数组(单点更新与区间求和)
- 共模电压和差模电压
- 人机交互界面设计
- Git冲突:commit your changes or stash them before you can merge.
- 使用svn开发,目录的约定与开发流程
- 实况足球2011免费游戏
- 树状数组扩展(异或求和)
- Ubuntu 出现apt-get: Package has no installation candidate问题
- bower常用配置项
- GitHub详细教程
- Maximum execution time of 30 seconds exceeded
- 它好要购买G五G3000手机
- c# XML操作
- [Java]Object类的toString()方法
- 外包Java开发