Clarke and Puzzle
Time limit:4000/2000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 673 Accepted Submission (s): 223
Problem Descriptionclarke is a patient with multiple personality disorder. One day, Clarke split to personalityaandb, they is playing a game.
There is an∗m Matrix, each grid of the This matrix have a numbercI,J .
aWants to beatbEvery time, soaask you to help.
There isQOperations, each of them are belonging to one of the following of the types:
1. They play the game on a ( Span id= "mathjax-span-36" class= "Msubsup" >x 1, y1 ) − (x 2, Y2) Sub matrix. They take turns operating. On any turn, the player can choose a grid which have a positive integer from the sub matrix and decrease it by a positive I Nteger which less than or equal this grid ' s number. The player can ' t operate is loser.aAlways operate first, he wants to know if he can win the this game.
2. ChangecI,J to b.
Inputthe first line contains a integerT(1≤t≤5) , the number of test cases.
For each test case:
The first line contains three integersN,M,q(1≤n,m≤,1≤q≤2∗5 )
Thenn∗m Matrix follow, theIRowJColumn is a integerCi,J(0≤ci,j≤9)
ThenQLines follow, the first number isopt .
Ifopt=1 , then4IntegersX1,Y1,X1,Y2(1≤x1 ≤x2≤n,1< Span id= "mathjax-span-189" class= "Mo" >≤y1≤y 2≤ m) Follow, represent operation1.
Ifopt=2 , then 3 integers i,J,b follow, represent operation 2.
Outputfor each testcase, for each operation1, print Yes if a can win this game, otherwise print No. /c12>
Sample Input11 2 31 21 1 1 1 22 1 2 11 1 1 1 2
Sample Outputyesno hint:the First enquiry: $a $ can decrease grid $ (1, 2) $ ' s number by $1$. No matter what $b $ operate next, there are always the one grid with number $1$ remaining. So, $a $ wins. The second enquiry:no matter what $a $ operate, there are always one grid with number $1$ remaining. So, $b $ wins.
Sourcebestcoder Round #56 (Div.2) topic: give you T group test data. There is a set of n,m,q in each set of test data, which indicates a matrix of n*m, and Q Group is asked. In each set of queries, action 1 indicates whether the query (X1,Y1)---(x2,y2) does the Nim game in the Matrix will win. Action 2 indicates that you want to modify a value in the matrix to C. Knowledge Supplement: See more of one-dimensional tree arrays. Two-dimensional still see less (weak). Then the difference between two-dimensional and one-dimensional is: the general meaning of the two-dimensional to seek is the Matrix and. For C[x][y], the definition here is from the elements of the (x, y)---matrix. We can abstract each line into a single point, which in fact is an abstraction to a one-dimensional situation. In fact, one-dimensional and two-dimensional implementation of the difference is easy to think of. For the two-dimensional bit, we get the C array, which requires N^2log (n) ^2 time complexity. Sum:
int sum (int x,int y) { int ret=0; For (Int. i=x;i>0;i-=lowbit (i)) {for (int j=y;j>0;j-=lowbit (j)) { ret+=c[i][j]; } } return ret;}
Modify:
void Modify (int x,int y,int val) {for (int. i=x;i<=n;i+=lowbit (i)) {for (int j=y;j<=m;j+=lowbit (j) ) { C[I][J] + = val;}}}
Problem Solving Ideas:
#include <bits/stdc++.h>using namespace Std;typedef long long int;const INT maxn=550;int a[maxn][maxn];int C[MAXN] [Maxn];int n,m;int lowbit (int x) {return x & (-X);} void Modify (int x,int y,int val) {for (Int. i=x;i<=n;i+=lowbit (i)) {for (int j=y;j<=m;j+=lowbit (j)) { C[I][J] ^= Val; }}}int sum (int x,int y) {int ret=0; For (Int. i=x;i>0;i-=lowbit (i)) {for (int j=y;j>0;j-=lowbit (j)) {ret ^=c[i][j]; }} return ret;} int main () {int t,q; scanf ("%d", &t); while (t--) {memset (a,0,sizeof (a)); memset (c,0,sizeof (C)); scanf ("%d%d%d", &n,&m,&q); for (int i=1;i<=n;i++) {for (int j=1;j<=m;j++) {scanf ("%d", &a[i][j]); }} for (int i=1;i<=n;i++) {for (int j=1;j<=m;j++) {modify (i,j,a[i][j]); }} int typ,x1,x2,y1,y2,c; for (int i=0;i<q;i++) { scanf ("%d", &typ); if (typ==1) {scanf ("%d%d%d%d", &x1,&y1,&x2,&y2); int ans1,ans2,ans3,ans4; Ans1=sum (X2,Y2); Ans2=sum (x2,y1-1); Ans3=sum (X1-1,Y2); Ans4=sum (x1-1,y1-1); int ans=ans1^ans2^ans3^ans4; printf ("%s\n", ans==0?) No ":" Yes "); }else{scanf ("%d%d%d", &x1,&y1,&c); Modify (X1,y1,c^a[x1][y1]); A[x1][y1]=c; }}} return 0;}
HDU 5465--clarke and puzzle —————— "tree array bit maintenance prefix and +nim game"