Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 33932 | Accepted: 10231 |
Description
Input
Output
Sample Input
2 2 4
C 1 1 2
P 1 2
C 2 2 2
P 1 2
Sample Output
2
1
Source
#include <cstdio> #include <cstring> #include <algorithm> using namespace std ; #define lson l , m , o << 1 #define rson m + 1 , r , o << 1 | 1 const int maxN = 1000005 ; int hash[maxN] , mark[maxN] ; void swap ( int &A , int &B ) { int tmp = A ; A = B ; B = tmp ; } void Build ( int l , int r , int o ) { hash[o] = 1 ; mark[o] = -1 ; if ( l == r ) return ; int m = ( l + r ) >> 1 ; Build ( lson ) ; Build ( rson ) ; } void PushUp ( int o ) { hash[o] = hash[o << 1] | hash[o << 1 | 1] ; } void PushDown ( int o ) { if ( ~mark[o] ) { mark[o << 1] = mark[o << 1 | 1] = mark[o] ; hash[o << 1] = hash[o << 1 | 1] = ( 1 << mark[o] ) ; mark[o] = -1 ; } } void Update ( int L , int R , int v , int l , int r , int o ) { if ( L <= l && r <= R ) { mark[o] = v ; hash[o] = ( 1 << v ) ; return ; } PushDown ( o ) ; int m = ( l + r ) >> 1 ; if ( L <= m ) Update ( L , R , v , lson ) ; if ( m < R ) Update ( L , R , v , rson ) ; PushUp ( o ) ; } int Query ( int L , int R , int l , int r , int o ) { if ( L <= l && r <= R ) return hash[o] ; PushDown ( o ) ; int ans = 0 , m = ( l + r ) >> 1 ; if ( L <= m ) ans |= Query ( L , R , lson ) ; if ( m < R ) ans |= Query ( L , R , rson ) ; return ans ; } void work () { int n , m , t , L , R , V ; char ch[5] ; while ( ~scanf ( "%d%d%d" , &n , &t , &m ) ) { Build ( 1 , n , 1 ) ; while ( m -- ) { scanf ( "%s%d%d" , ch , &L , &R ) ; if ( L > R ) swap ( L , R ) ; if ( ch[0] == 'C' ) { scanf ( "%d" , &V ) ; Update ( L , R , V - 1 , 1 , n , 1 ) ; } else { int ans = Query ( L , R , 1 , n , 1 ) , count = 0 ; for ( int i = t - 1 ; i >= 0 ; -- i ) { if ( ans & ( 1 << i ) ) ++ count ; } printf ( "%d\n" , count ) ; } } } } int main () { work () ; return 0 ; }