-
-
Save saisumit/0dedc5771d4171f2a13761b7330fcfa0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int MAXN = 3e5 + 50 ; | |
int A[ MAXN ] ; | |
int S[ MAXN ] ; | |
int T[ 4*MAXN ] ; | |
int N ; | |
int LB = -1 ; | |
int UB = INT_MAX; | |
int Case1( int idx ) | |
{ | |
int Limit = ( 1 << idx ); | |
if( S[idx] < Limit )return 0 ; | |
int cnt1 = X.order_of_key( mp( 0 , LB ) ) ; // jo 0 se strictly chote hain | |
int cnt2 = X.order_of_key( mp( S[idx] - Limit , UB ) ) ; | |
return cnt2 - cnt1 ; | |
} | |
int Case2 ( int idx ) | |
{ | |
int Limit = ( 1 << idx ) ; | |
int cnt1 = X.order_of_key( mp( S[idx]+1 , LB ) ) ; // jo 0 se strictly chote hain | |
int cnt2 = X.order_of_key( mp( S[idx] + Limit , UB ) ) ; | |
return cnt2 - cnt1 ; | |
} | |
bool check ( int idx ) | |
{ | |
X.clear() ; | |
const int M = ( 1 << (idx + 1) ) ; | |
S[0] = A[0]%M ; | |
for( int i = 1 ; i < N ; i ++ ) | |
S[i] = ( S[i-1] + A[i] )%M ; | |
//! Case 1 : S[j] >= 0 and S[i] - 2^b | |
//! Case 2 : S[i] + 1 and S[i] + 2^b | |
int sum = 0 ; | |
FOR( i , N ) | |
{ | |
if( (1<<idx) & A[i] )sum ++ ; | |
sum += Case1 ( i ) ; | |
cout<<sum<<endl; | |
sum += Case2 ( i ) ; | |
cout<<sum<<endl; | |
X.insert(mp(S[i],i)) ; | |
} | |
cout<<idx<<" "<<sum<<endl; | |
return (sum&1); | |
} | |
int main ( ) | |
{ | |
scanf("%d",&N) ; | |
FOR( i , N )scanf("%d",&A[i] ) ; | |
int ans = 0 ; | |
for( int i = 0 ; i < 31 ; i ++ ) | |
if( check( i ) )ans = ans | ( 1 << i ) ; | |
cout<<ans<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment