poj 2155 二维树状数组
2014-07-16 20:21
302 查看
还是注意向上向下更新,一对点表示包含一个区域
AC代码如下:
AC代码如下:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAX_N = 1000; int sum[MAX_N+5][MAX_N+5]; int N; inline int lowbit( int x ){ return x & ( -x ); } void updata( int x, int y, int val ){ for( int i = x; i <= N; i += lowbit( i ) ){ for( int j = y; j <= N; j += lowbit( j ) ){ sum[i][j] = ( sum[i][j] + val ) % 2; } } } int getsum( int x, int y ){ int ans = 0; for( int i = x; i > 0; i -= lowbit( i ) ){ for( int j = y; j > 0; j -= lowbit( j ) ){ ans = ( sum[i][j] + ans ) % 2; } } return ans; } int main(){ int T; scanf( "%d", &T ); while( T-- ){ int temp; scanf( "%d%d", &N, &temp ); memset( sum, 0, sizeof( sum ) ); while( temp-- ){ char t[10]; scanf( "%s", t ); if( t[0] == 'C' ){ int temp1, temp2, temp3, temp4; scanf( "%d%d%d%d", &temp1, &temp2, &temp3, &temp4 ); updata( temp1, temp2, 1 ); updata( temp1, temp4 + 1, 1 ); updata( temp3 + 1, temp2, 1 ); updata( temp3 + 1, temp4 + 1, 1 ); }else{ int temp1, temp2; scanf( "%d%d", &temp1, &temp2 ); printf( "%d\n", getsum( temp1, temp2 ) ); } } printf( "\n" ); } return 0; }
相关文章推荐
- poj 2155 Matrix(二维树状数组)(经典)
- poj 2155 Matrix (二维树状数组)
- 01变换 二维树状数组+区间更新,单点查询 poj 2155 Matrix
- POJ-2155(二维树状数组)
- poj 2155(二维树状数组)
- POJ-2155:Matrix(二维线段树或二维树状数组)
- POJ2155 Matrix(二维树状数组)
- POJ - 2155 Matrix (二维树状数组)
- poj 2155 Matrix(二维树状数组)(经典)
- POJ 2155 Matrix (二维树状数组+经典题)
- poj 2155 Matrix(二维树状数组)(经典)
- poj 2155 Matrix(二维树状数组) hdu 3584 Cube(三维)
- poj 2155 Matrix (二维树状数组)
- [poj 2155] Matrix(二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- poj 2155 Matrix(二维树状数组)
- poj2155 Matrix 二维树状数组
- POJ 2155 (二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- POJ 2155 Matrix(二维树状数组)