Codeforces Round 341D

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 5
2 1 1 2 2 1
2 1 3 2 3 2
2 3 1 3 3 3
1 2 2 3 3
1 2 2 3 2
output
3
2
Note

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

1 1 2
1 1 2
3 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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值