hdu5892Resident Evil(2016沈阳网络赛A)
2016-09-19 17:45
253 查看
hdu5892ResidentEvil(2016沈阳网络赛A)
裸的二维树状数组求和,比赛的时候竟然没发现。实际上XOR运算等效于模2意义下的加减运算。这题唯一用到的技巧是将50个怪兽的状态压缩成250统一处理以节省时间空间。至于二维树状数组区间求和和查询,可以通过推公式的方法先将问题转化成单点修改,区间查询,再用矩形加减即可。
最后注意一次修改同一只怪兽可能出现多次,还有PE问题,行末没空格算PE ⊙﹏⊙。
//#include <bits\stdc++.h> //#pragma comment(linker,"/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <iostream> #include <cstdlib> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <ctime> #include <cmath> #include <algorithm> #include <bitset> #define sqr(x) ((x)*(x)) #define lson (p<<1) #define rson (lson | 1) #define EPS 1e-10 #define PII pair<int,int> #define PLI pair<LL,int> #define PLL pair<LL,LL> #define PIL pair<int,LL> #define mk(x,y) make_pair(x,y) #define lowbit(x) (x&(-x)) using namespace std; template <class T> inline void read(T &x){char c = getchar();x = 0;while(!isdigit(c))c = getchar();while(isdigit(c)){ x = x * 10 + c-'0';c = getchar();}} template <class T> inline void rd(T &res) {static char ch; boolsgn = false;while (ch = getchar(), ch <'0' || ch > '9') if (ch == '-') sgn =true; res = ch - 48;while(ch = getchar(), ch >= '0' && ch<= '9') res = res * 10 + ch - 48;res = sgn ? -res : res;} template <class T> void Out(T a) { if(a < 0){putchar('-');a= -a;}if(a >= 10)Out(a / 10);putchar(a% 10 + '0'); } typedef unsigned long long LL; const int N = 3010; LL c[4] ; int n; void add(int id,int x,int y,LL val) { for(;x<=n;x+=lowbit(x)) for(int j=y;j<=n;j+=lowbit(j)) c[id][x][j]^= val; } void add(int x,int y,LL val) { add(0,x,y,val); if(y&1) add(1,x,y,val); if(x&1) add(2,x,y,val); if((x*y)&1)add(3,x,y,val); } void update(int x1,int y1,int x2,int y2,LLx) { add(x1,y1,x),add(x1,y2,x),add(x2,y1,x),add(x2,y2,x); } LL get(int id,int x,inty) { LL ans = 0; for(;x;x-=lowbit(x)) for(int j=y;j;j-=lowbit(j)) ans ^= c[id][x][j]; return ans; } LL get(int x,int y) { LL ans = get(3,x,y); int xx = x + 1,yy = y + 1; if( (xx*yy) & 1)ans ^= get(0,x,y); if( (xx) & 1)ans ^= get(1,x,y); if( (yy) & 1)ans ^= get(2,x,y); return ans; } LL query(int x1,int y1,intx2,int y2) { return get(x2,y2)^ get(x1,y2) ^ get(x2,y1) ^ get(x1,y1); } char s[10]; LL Pow[55]; int main() { int m; Pow[0] = 1; for(int i=1;i<55;i++) Pow[i] = Pow[i-1] << 1LL; while(~scanf("%d%d",&n,&m)) { memset(c,0,sizeof(c)); while(m--) { int x1,y1,x2,y2,k,l,r; scanf(" %s",s); rd(y1),rd(x1),rd(y2),rd(x2); if(s[0] == 'P') { rd(k); LL x = 0; while(k--) { rd(l),rd(r); if(r&1) x^=Pow[l]; } update(x1,y1,x2+1,y2+1,x); }else { LL ans = query(x1-1,y1-1,x2,y2); for(int i=1;i<=50;i++) { if(ans&Pow[i]) putchar('2'); elseputchar('1'); putchar(' '); } puts(""); } } } return 0; }
相关文章推荐
- Hdu5893树链剖分(2016沈阳网络赛B)
- hdu 5950 2016ACM/ICPC沈阳赛区现场赛C题【矩阵快速幂】
- 2016 沈阳 1003 Recursive sequence(hdu 5950)矩阵快速幂
- hdu 5952 Counting Cliques 暴力搜索 2016沈阳区域赛
- HDU5950 - 变形斐波拉契+矩阵快速幂-2016ICPC亚洲赛沈阳
- HDU 5894 hannnnah_j’s Biological Test (组合数学) -2016 ICPC沈阳赛区网络赛
- AC自动机+高斯消元求解线性方程--2016icpc沈阳H
- 2016 acm/icpc 沈阳现场赛题解(5道题,更新ing)
- hdu5894 hannnnah_j’s Biological Test(2016 acm/icpc 沈阳网络赛,组合数学)
- hdu 5898 odd-even number 2016ACM/ICPC沈阳赛区网络赛1007
- [2016ICPC 沈阳网络预选赛] HDU 5894 排列组合
- HDU5892~HDU5901 2016网络赛沈阳
- hdu5459(2015沈阳网络赛J题)
- 2016 沈阳区域赛第三题(Recursive sequence)(矩阵快速幂)
- Hdu 5952 Counting Cliques(2016沈阳网络赛)
- 2016ICPC-沈阳行
- hdu5452(2015沈阳网络赛C题)
- 2016 沈阳 大致题意
- hdu5900(2016沈阳网络赛1009区间dp)
- hdu5952 Counting Cliques(2016 icpc 沈阳)