Test instructions: Given two kinds of operations, C is to give a rectangle's upper left and bottom left-hand corner of the subscript, the rectangle inside the 0 into 1, 1 to 0,q is to ask for a point value
See, this paper is very clear.
Http://wenku.baidu.com/view/1e51750abb68a98271fefaa8
Look at the time, each point corresponding to cover which areas to draw out, and then combine the paper inside, good understanding some
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A -typedefLong LongLL; - Const intINF = (1<< -)-1; the Const intMod=1000000007; - Const intmaxn=1005; - - intN; + intC[MAXN][MAXN]; - + intLowbit (intx) {returnX & (-x);} A at intSumintXinty) { - intret=0, y1; - while(x>0){ -y1=y; - while(y1>0){ -ret+=c[x][y1];y1-=lowbit (y1); in } -x-=lowbit (x); to } + returnret; - } the * voidAddintXintYintd) { $ intY1;Panax Notoginseng while(x<=N) { -y1=y; the while(y1<=N) { +c[x][y1]+=d;y1+=lowbit (y1); A } thex+=lowbit (x); + } - } $ $ intMain () { - intT; -scanf"%d",&T); the while(t--){ - intm;WuyiMemset (c,0,sizeof(c)); thescanf"%d%d%*c",&n,&m); - while(m--){ Wu Charch; -scanf"%c",&ch); About if(ch = ='C'){ $ intX1,y1,x2,y2; -scanf"%d%d",&x1,&y1); -scanf"%d%d%*c",&x2,&y2); -Add (X1,y1,1); AAdd (x1,y2+1,-1); +Add (x2+1, y1,-1); theAdd (x2+1, y2+1,1); - } $ Else { the intL,r; thescanf"%d%d%*c",&l,&R); the intans; theans=sum (l,r); -printf"%d\n", ans%2); in } the } the if(t>=1) puts (""); About } the return 0; the}
View Code
POJ 2155 Matrix "Two-dimensional tree-like array"