hdu 5892 List wants to travel 2016ACM/ICPC沈阳赛区网络赛1001

来源:互联网 发布:淘宝上卖高仿鞋的店 编辑:程序博客网 时间:2024/05/22 03:37

Problem Description
The Umbrella Company has developed a new biochemical virus secretly. Lyon, a staff of the company, happened to find out the conspiracy and his company is now stopping him from discovering further evidence by releasing biochemical monster in his city (don’t ask me why the company is using this weird method).

The city can be described as an n*n grids. The Umbrella Company has 50 kinds of biochemical monster in total. The company will specify the type, quantity of biochemical monster and the rectangle area to put monster. For example, if the specified rectangle area has upper left corner (1, 1) and bottom right corner of (3, 3), and the company wishes to put 3 of A monster, 2 of B monster and 1 of C monster in it, then 3 of A monster, 2 of B monster and 1 of C monster is added to each and every grid inside the area.

However, Lyon risk his life of finding evidence by searching certain rectangle area. By doing this, all monsters inside the area would gather to him. He has two way of dealing with monster. If the number of a certain kind of monster is even, then he would choose to hide, otherwise withdraw.
 

Input
A line containing n and m (1<=n<=3000 1<=m<=100000). Representing the size of the city and the number of operations.

  Then m lines of operation and there are only two kinds of operation.

Letter ‘P’ means to release monster, followed by 4 integers x1, y1, x2, y2 (1<=x1, y1, x2, y2<=n) , describing the upper left corner and bottom right corner of the area. Then an integer K(1<=K<=50), meaning there will be k pair of number (A, B) given next. A (1<=A<=50) indicates the kind of the monster and B (1<=b<=100000) indicates the number of this kind being added to this area.

Letter ‘Q’ represents the query operation, followed by 4 integers x1, y1, x2, y2 (1<=x1, y1, x2, y2<=n), describing the upper left corner and bottom right corner of the area.
 

Output
For every ‘Q’ operation. Print 50 number in a line, meaning the kind of action he would take for different kinds of monsters. 1 represents hiding and 2 represents withdrawing.
 

Sample Input
2 2P 1 1 2 2 1 1 1 Q 1 1 1 1
 

Sample Output
2 1 1 1 1 1 ........1 (one '2' and forty-nine '1')

四个树状数组维护。。具体看传送门

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][3002][3002];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(){while(scanf("%d%d",&n,&m)!=EOF){memset(tr,0,sizeof(tr));int i,j,x1,y1,x2,y2,k,x,y;string xx;for(i=1;i<=m;i++){cin>>xx;if(xx=="P"){scanf("%d%d%d%d",&x1,&y1,&x2,&y2);scanf("%d",&k);long long del=0;for(j=1;j<=k;j++){scanf("%d%d",&x,&y);if(y%2==1)del^=((long long)1<<(long long)(x-1));}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);         for(j=1;j<=50;j++)         {         if((ans1&((long long)1<<(long long)(j-1))))         printf("2 ");         else         printf("1 ");         }         printf("\n");}}}return 0;}


0 0