Codeforces D. Iahub and Xors

 题目大意:给定一个N*N的区间,1:对(x0,y0,x1,y1)每个直 都xor v;

                                                     2: 求(x0,y0,x1,y1)区间的 sum xor;

http://codeforces.com/blog/entry/8755    

算得上经典题:

       

 1 #include<stdio.h>
 2 #include<algorithm>
 3 #include<math.h>
 4 #include<vector>
 5 #include<string.h>
 6 #include<string>
 7 #include<set>
 8 #include<map>
 9 #include<iostream>
10 #include<set>
11 
12 using namespace std;
13 typedef long long ll;
14 int n;
15 
16 ll c[2][2][1003][1003];
17 
18 ll query(int x,int y)
19 {
20  ll ret=0;
21  for (int i=x;i>0;i-=i&-i)
22  for (int j=y;j>0;j-=j&-j)
23  ret^=c[x&1][y&1][i][j];
24  return ret;
25 }
26 
27 void update(int x,int y,ll v)
28 {
29    for (int i=x;i<=n;i+=i&-i)
30    for (int j=y;j<=n;j+=j&-j)
31    c[x&1][y&1][i][j]^=v;
32 }
33 
34 int main()
35 {
36    int m,x,y,xx,yy,op;
37    ll v;
38    scanf("%d%d",&n,&m);
39    while (m--)
40    {
41      scanf("%d%d%d%d%d",&op,&x,&y,&xx,&yy);
42      if (op==1)
43      {
44        x--;
45        y--;
46        printf("%I64d\n",query(x,y)^query(x,yy)^query(xx,y)^query(xx,yy));
47      }
48      else
49      {
50         scanf("%I64d",&v);
51         xx++;
52         yy++;
53         update(x,y,v);
54         update(xx,yy,v);
55         update(x,yy,v);
56         update(xx,y,v);
57      }
58    }
59    return 0;
60 }

 

posted on 2015-07-06 20:03  forgot93  阅读(344)  评论(0编辑  收藏  举报

导航