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 ≤ x1, y0 ≤ j ≤ y1.
Write a program to perform two following operations:
- Query(x0, y0, x1, y1): print the xor sum of the elements of the submatrix (x0, y0, x1, y1).
- Update(x0, y0, x1, y1, v): each element from submatrix (x0, y0, x1, y1) gets xor-ed by value v.
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 x0, y0, x1, y1. 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 x0, y0, x1, y1, v.
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 ≤ n, 1 ≤ y0 ≤ y1 ≤ n.
For each query operation, output on a new line the result.
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
32
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;}
- Codeforces Round 341D
- Codeforces Round#213D
- Codeforces Round#131D
- Codeforces Round #428 D
- Codeforces Round #433 D
- codeforces round #441 D
- CodeForces Round 230 Div2 D
- codeforces div2 round#230 D
- Codeforces Round #270 A~D
- Codeforces Round #317div2 D
- Codeforces Round #339 D. Skills
- codeforces round#377 div2 D
- codeforces Round #382(Div2) D
- Codeforces Round #409 div2 D
- Educational Codeforces Round 21-D
- Educational Codeforces Round 5 D
- Codeforces 837 D Round Subset
- Educational Codeforces Round 26 D
- 单链表应用问题--课本素材
- red-black tree
- auto,register,extern,static使用及区别
- CocoPods基本使用
- [Python]网络爬虫(二):利用urllib2通过指定的URL抓取网页内容
- Codeforces Round 341D
- 通用Adapter设计,SparseArray+泛型+回调的使用
- UVa OJ 12265 - Selling Land
- Java数组
- HTTP协议入门
- Ubuntu安装和配置SVN
- (C++水过去的)Power of Cryptography
- java反射机制创建对象
- 如何使用Material Design中的BottomSheetBehavior、BottomSheetDialog和BottomSheetDialogFragment