problem Description
Clarke isa patient with multiple personality disorder. One day, Clarke split into personality A and B, they is playing a game. There isA n∗m matrix, each grid of ThisMatrix has a number ci,j. A wants to beat B every time, so a ask you fora Help. There is Q operations, each of them isBelonging to one of the following-types:1. They play the game on a (x1,y1) − (x2,y2) sub matrix. They take turns operating. On any turn, the player can choose a grid which have a positive integer fromThe sub matrix and decrease it by a positive integer which less than or equal ThisGrid's number. The player who can'T operate isLoser. A always operate first, he wants to knowifHe can win Thisgame.2. Change Ci,j to B.
Input
The first line contains a integer T (1≤t≤5), the number of test cases. for each test Case: The first line contains three integers n,m,q (1≤n,m≤ -,1≤q≤2∗ the) then n∗m matrix follow, the I row J column isA integer ci,j (0≤ci,j≤109) then Q lines follow, the first number isopt.ifopt=1, then4Integers X1,y1,x1,y2 (1≤x1≤x2≤n,1≤Y1≤Y2≤M) follow, represent operation1. ifopt=2, then3Integers i,j,b follow, represent operation2.
Output
for 1 if this game, otherwise print No.
Sample Input
1 1 2 3 1 2 1 1 1 1 2 2 1 2 1 1 1 1 1 2
Sample Output
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.
Source
bestcoder Round #56 (Div.2)
The topic requires a two-dimensional NIM game, considering that Nim's conclusion is XOR and 0 will fail, otherwise win, then we only need to maintain the sub-matrix XOR and. Because XOR has a prefix and nature, we can use a two-dimensional bit to maintain (1, 1)-(A, B) the XOR of the Matrix, and then by theSUM (x2,y2) XOR sum (x2,y1−1) XOR sum (x1−1,y2) XOR sum (x1−1,y1−1) sum (x2, y2) \ xor \ sum (x2, y1-1) \ XOR \ sum (x1-1, y2) \ x or \ sum (x1-1, y1-1)SUM(X2,Y2)XORSUM(X2,Y1−1)XOR sum (x1−1,y2) xor sum ( Span class= "Mord mathit" >x1−1,< Span class= "Mord mathit" >y1−1) To get the answer. A single point of modification is easy on the bit.
1 #pragmaComment (linker, "/stack:1024000000,1024000000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <math.h>7#include <algorithm>8#include <queue>9#include <Set>Ten#include <bitset> One#include <map> A#include <vector> -#include <stdlib.h> -#include <stack> the using namespacestd; - intdirx[]={0,0,-1,1}; - intdiry[]={-1,1,0,0}; - #definePI ACOs (-1.0) + #defineMax (a) (a) > (b)? (a): (b) - #defineMin (a) (a) < (b)? (a): (b) + #definell Long Long A #defineEPS 1e-10 at #defineMOD 1000000007 - #defineN 506 - #defineINF 1e12 - intn,m,q; - intMp[n][n]; - intA[n][n]; in intMain () - { to intT; +scanf"%d",&t); - while(t--){ thescanf"%d%d%d",&n,&m,&q); * for(intI=1; i<=n;i++){ $ for(intj=1; j<=m;j++){Panax Notoginsengscanf"%d",&mp[i][j]); -a[i][j]=a[i][j-1]^Mp[i][j]; the } + } A for(intI=0; i<q;i++){ the intopt; +scanf"%d",&opt); - intx, y, z $ if(opt==2){ $scanf"%d%d%d",&x,&y,&z); -mp[x][y]=Z; - for(intj=y;j<=m;j++){ thea[x][j]=a[x][j-1]^Mp[x][j]; - }Wuyi } the Else{ - intans=0; Wu intX1,y1,x2,y2; -scanf"%d%d%d%d",&x1,&y1,&x2,&y2); About for(intj=x1;j<=x2;j++){ $ans=ans^ (a[j][y2]^a[j][y1-1]); - } - if(ans==0){ -printf"no\n"); A } + Else{ theprintf"yes\n"); - } $ } the } the } the return 0; the}
View Code
HDU 5465 Clarke and puzzle (prefix and, XOR, Nim game)