HDU5456 二维树状数组+nim博弈
来源:互联网 发布:snmp 端口 编辑:程序博客网 时间:2024/05/17 04:53
异或和
import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.io.PrintWriter;import java.math.BigInteger;import java.util.StringTokenizer;public class Main {public static void main(String[] args) {new HDU5465().solve();}}class HDU5465 {InputReader in = new InputReader(System.in);PrintWriter out = new PrintWriter(System.out);Bit bit = new Bit() ;void solve() { int t = in.nextInt() ; while(t-- > 0){ int n = in.nextInt() ; int m = in.nextInt() ; bit.resize(n, m) ; int q = in.nextInt() ; for(int i = 1 ; i <= n ; i++){ for(int j = 1 ; j <= m ; j++) bit.add(i, j, in.nextInt()) ; } while(q-- > 0){ if(in.nextInt() == 1){ if(bit.query(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()) != 0) out.println("Yes") ; else out.println("No") ; } else bit.update(in.nextInt() , in.nextInt() , in.nextInt()) ; } } out.flush() ;}}class Bit{final int N = 508 ;int[][] val = new int[N][N] ;int n , m ;void resize(int n , int m){this.n = n ;this.m = m ; for(int i = 1 ; i <= n ; i++) for(int j = 1 ; j <= m ; j++) val[i][j] = 0 ; }int lowbit(int x){return x & (-x) ;}void add(int i , int j , int c){for(int x = i ; x <= n ; x += lowbit(x))for(int y = j ; y <= m ; y += lowbit(y)) val[x][y] ^= c ;}int sum(int i , int j){int res = 0 ;for(int x = i ; x > 0 ; x -= lowbit(x))for(int y = j ; y > 0 ; y -= lowbit(y)) res ^= val[x][y] ; return res ;}int query(int x1 , int y1 , int x2 , int y2){return sum(x2, y2) ^ sum(x2, y1-1) ^ sum(x1-1, y2) ^ sum(x1-1, y1-1) ;}void update(int x , int y , int c){add(x, y, query(x, y, x, y)) ;add(x, y, c) ;}}class InputReader {public BufferedReader reader;public StringTokenizer tokenizer;public InputReader(InputStream stream) {reader = new BufferedReader(new InputStreamReader(stream), 32768);tokenizer = new StringTokenizer("") ;}private void eat(String s){tokenizer = new StringTokenizer(s) ;}public String nextLine(){try {return reader.readLine() ;} catch (Exception e) {return null ;}}public boolean hasNext(){while(!tokenizer.hasMoreTokens()){String s = nextLine() ;if(s == null) return false ;eat(s) ;}return true ;}public String next() {hasNext() ;return tokenizer.nextToken();}public int nextInt() {return Integer.parseInt(next());}public long nextLong() {return Long.parseLong(next());}public double nextDouble() {return Double.parseDouble(next());}public BigInteger nextBigInteger() {return new BigInteger(next());}}
0 0
- HDU5456 二维树状数组+nim博弈
- hdu 5465 二维树状数组+nim博弈
- hdu 5465 Clarke and puzzle (二维树状数组+nim博弈)
- [BZOJ 2819]nim(DFS序+树状数组+SG博弈)
- pku1195 二维树状数组
- 二维树状数组
- 二维树状数组
- 树状数组 二维空间
- 二维树状数组
- 二维树状数组
- 二维树状数组
- POJ2155(二维树状数组)
- poj1195 二维树状数组
- 二维树状数组
- poj1195(二维树状数组)
- hdu1892二维树状数组
- 二维树状数组-poj2155
- 二维树状数组--poj1195
- 《手把手博客搭建教程1—架构选择》
- spring mvc xss filter
- EventBus(二)------从register这条线分析EventBus
- 关于java插入到mysql数据库出现乱码
- Cesium 概述 (二) 空间数据可视化
- HDU5456 二维树状数组+nim博弈
- 栈的应用--递归与四则运算表达式求值
- SqlAlchmy Session的线程安全问题
- iOS 添加事件到系统日历中
- iOS学习(十七)Objective-C 组合
- jQuery Validate 自定义验证方法引入问题
- 链表插入排序
- java 数据类型
- Handler消息传递机制