Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 10544 | Accepted: 3945 |
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
#include <cstring> #include <cstdlib> #include <cstdio> #define LSON p << 1 #define RSON p << 1 | 1 #define MID( x, y ) (x) + (y) >> 1 #define TWO( x, y ) (x) + (y) << 1 #define M( x, y ) memset( (x), (y), sizeof(x) ) using namespace std; struct node { int u, d, val; }n[2605][2605]; struct Node { int l, r; node *next; }N[2605]; int M, Q, ans; void y_build( node *r, int p, int u, int d ) { r[p].u = u, r[p].d = d, r[p].val = 0; if( d - u > 1 ) { int m = MID( d, u ); y_build( r, LSON, u, m ); y_build( r, RSON, m, d ); } } void build( int p, int l, int r ) { N[p].l = l, N[p].r = r, N[p].next = n[p]; if( r - l > 1 ) { int m = MID( l, r ); build( LSON, l, m ); build( RSON, m, r ); } y_build( n[p], 1, 1, M + 1 ); } void y_modify( node *r, int p, int u, int d ) { if( r[p].u == u && r[p].d == d ) { r[p].val ^= 1; return; } int m = MID( r[p].u , r[p].d ); if( m >= d ) y_modify( r, LSON, u, d ); else if( m <= u ) y_modify( r, RSON, u, d ); else { y_modify( r, LSON, u, m ); y_modify( r, RSON, m, d ); } } void modify( int p, int l, int r, int u, int d ) { if( N[p].l == l && N[p].r == r ) { y_modify( N[p].next, 1, u, d ); return; } int m = MID( N[p].l, N[p].r ); if( m >= r ) modify( LSON, l, r, u, d ); else if( m <= l ) modify( RSON, l, r, u, d ); else { modify( LSON, l, m, u, d ); modify( RSON, m, r, u, d ); } } void y_cal( node *r, int p, int u, int d ) { if( r[p].u <= u && r[p].d >= d ) { ans ^= r[p].val; if( r[p].d - r[p].u == 1 ) return; } int m = MID( r[p].u, r[p].d ); if( m >= d ) y_cal( r, LSON, u, d ); else if( m <= u ) { y_cal( r, RSON, u, d ); } } void cal( int p, int l, int r, int u, int d ) { if( N[p].l <= l && N[p].r >= r ) { y_cal( N[p].next, 1, u, d ); if( N[p].r - N[p].l == 1 ) return; } int m = MID( N[p].l, N[p].r ); if( m >= r ) cal( LSON, l, r, u, d ); else if( m <= l ) cal( RSON, l, r, u, d ); } int main() { int T; scanf( "%d", &T ); for( int t = 1; t <= T; ++t ) { char op[5]; int x1, x2, y1, y2; scanf( "%d %d", &M, &Q ); build( 1, 1, M + 1 ); for( int i = 0; i < Q; ++i ) { scanf( "%s", op ); if( op[0] == 'C' ) { scanf( "%d %d %d %d", &x1, &y1, &x2, &y2 ); modify( 1, x1, x2 + 1, y1, y2 + 1 ); } else { ans = 0; scanf( "%d %d", &x1, &y1 ); cal( 1, x1, x1 + 1, y1, y1 + 1 ); printf( "%d\n", ans ); } } if( t < T ) puts( "" ); } return 0; }