Codeforces Round 341D

来源:互联网 发布:淘宝信誉刷到皇冠 编辑:程序博客网 时间:2024/06/06 02:56

Iahub does not like background stories, so he'll tell you exactly what this problem asks you for.

You are given a matrix a with n rows and n columns. Initially, all values of the matrix are zeros. Both rows and columns are 1-based, that is rows are numbered 1, 2, ..., n and columns are numbered 1, 2, ..., n. Let's denote an element on the i-th row and j-th column as ai, j.

We will call a submatrix (x0, y0, x1, y1) such elements ai, j for which two inequalities hold: x0 ≤ i ≤ x1y0 ≤ j ≤ y1.

Write a program to perform two following operations:

  1. Query(x0y0x1y1): print the xor sum of the elements of the submatrix (x0, y0, x1, y1).
  2. Update(x0y0x1y1v): each element from submatrix (x0, y0, x1, y1) gets xor-ed by value v.
Input

The first line contains two integers: n (1 ≤ n ≤ 1000) and m (1 ≤ m ≤ 105). The number m represents the number of operations you need to perform. Each of the next m lines contains five or six integers, depending on operation type.

If the i-th operation from the input is a query, the first number from i-th line will be 1. It will be followed by four integers x0y0x1y1. If the i-th operation is an update, the first number from the i-th line will be 2. It will be followed by five integers x0y0x1y1v.

It is guaranteed that for each update operation, the following inequality holds: 0 ≤ v < 262. It is guaranteed that for each operation, the following inequalities hold: 1 ≤ x0 ≤ x1 ≤ n1 ≤ y0 ≤ y1 ≤ n.

Output

For each query operation, output on a new line the result.

Examples
input
3 52 1 1 2 2 12 1 3 2 3 22 3 1 3 3 31 2 2 3 31 2 2 3 2
output
32
Note

After the first 3 operations, the matrix will look like this:

1 1 21 1 23 3 3

The fourth operation asks us to compute 1 xor 2 xor 3 xor 3 = 3.

The fifth operation asks us to compute 1 xor 3 = 2.


做完沈阳网络赛顺便把这题做了。

具体见传送门

http://www.cnblogs.com/Kurokey/p/5887157.html

#include<map>#include<cmath>#include<queue>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int n,m;long long tr[2][2][1002][1002];inline int lowbit(int x){return x&(-x);}inline void add(int x,int y,long long xx){int i,j;for(i=x;i<=n;i+=lowbit(i))for(j=y;j<=n;j+=lowbit(j))tr[x&1][y&1][i][j]^=xx;}inline long long ask(int x,int y){int i,j;long long ans=0;for(i=x;i>=1;i-=lowbit(i))for(j=y;j>=1;j-=lowbit(j))ans^=tr[x&1][y&1][i][j];return ans;}int main(){int T;T=1;while(T>0){T--;//memset(tr,0,sizeof(tr));scanf("%d%d",&n,&m);int i,j,x1,y1,x2,y2,k,x,y;int xx;for(i=1;i<=m;i++){scanf("%d",&xx);if(xx==2){scanf("%d%d%d%d",&x1,&y1,&x2,&y2);long long del=0;scanf("%I64d",&del);add(x1,y1,del);add(x1,y2+1,del);add(x2+1,y1,del);add(x2+1,y2+1,del);}else{scanf("%d%d%d%d",&x1,&y1,&x2,&y2);         long long ans1=ask(x1-1,y1-1)^ask(x1-1,y2)^ask(x2,y1-1)^ask(x2,y2);         printf("%I64d\n",ans1);}}}return 0;}



0 0
原创粉丝点击