Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 17423 | Accepted: 6530 |
Description
Input
Output
Sample Input
1
2 10
C 2 1 2 2
Q 2 2
C 2 1 2 1
Q 1 1
C 1 1 2 1
C 1 2 1 2
C 1 1 2 2
Q 1 1
C 1 1 2 1
Q 2 1
Sample Output
1
0
0
1
Source
#include <cstdio> #include <cstring> #include <algorithm> using namespace std ; #define clear( A , X ) memset ( A , X , sizeof A ) #define lson l , m , o << 1 #define rson m + 1 , r , o << 1 | 1 #define LxRxLyRy Lx , Rx , Ly , Ry const int maxN = 1005 ; bool sum[ maxN << 2 ][ maxN << 2 ] ; int n; void YUpdate ( int L, int R , int l , int r , int o , int x ) { if ( L <= l && r <= R ) sum[ x ][ o ] ^= 1 ; else { int m = ( l + r ) >> 1 ; if ( L <= m ) YUpdate ( L , R , lson , x ) ; if ( m < R ) YUpdate ( L , R , rson , x ) ; } } void XUpdate ( int Lx , int Rx , int Ly , int Ry , int l , int r , int o ) { if ( Lx <= l && r <= Rx ) { YUpdate ( Ly , Ry , 1 , n , 1 , o ) ; } else { int m = ( l + r ) >> 1 ; if ( Lx <= m ) XUpdate ( LxRxLyRy , lson ) ; if ( m < Rx ) XUpdate ( LxRxLyRy , rson ) ; } } bool YQuery ( int Y , int l , int r , int o , int x ) { bool ans = 0 ; ans ^= sum[ x ][ o ] ; if ( l == r ) return ans; int m = ( l + r ) >> 1; if ( Y <= m ) ans ^= YQuery ( Y , lson , x ) ; else ans ^= YQuery ( Y , rson , x ) ; return ans ; } bool XQuery ( int X , int Y , int l , int r , int o ) { bool ans = 0 ; ans ^= YQuery ( Y , 1 , n , 1 , o ) ; if ( l == r ) return ans; int m = ( l + r ) >> 1 ; if ( X <= m ) ans ^= XQuery ( X , Y , lson ) ; else ans ^= XQuery ( X , Y , rson ) ; return ans ; } void work ( int m ) { clear ( sum , 0 ) ; char ch[ 5 ] ; int x1 , y1 , x2 , y2 , X , Y; while ( m -- ) { scanf ( "%s" , ch ) ; if ( ch[ 0 ] == 'C' ) { scanf ( "%d%d%d%d" , &x1 , &y1 , &x2 , &y2 ) ; XUpdate ( x1 , x2 , y1 , y2 , 1 , n , 1 ) ; } if ( ch[ 0 ] == 'Q' ) { scanf ( "%d%d" , &X, &Y ) ; printf ( "%d\n" , XQuery ( X , Y , 1 , n , 1 ) ) ; } } } int main () { int m , T ; for ( scanf ( "%d" , &T ) ; T ; -- T ) { scanf ( "%d%d" , &n , &m ) ; work ( m ) ; if ( T > 1 ) printf ( "\n" ) ; } return 0 ; }