1872E - Data Structures Fan - CodeForces Solution


bitmasks

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define ll long long int

using namespace std;


int main(){
    ll t;
    cin>>t;
    while(t--){
    	ll n;
    	cin>>n;
    	ll a[n];
    	for(int i=0;i<n;i++){
    		cin>>a[i];
    	}
    	string s;
    	cin>>s;
    	ll a1[n+1];
    	ll a0[n+1];
    	for(int i=0;i<=n;i++){
    		a1[i]=0;
    		a0[i]=0;
    	}
    	if(s[0]=='0') a0[1]=a[0];
    	if(s[0]=='1') a1[1]=a[0];
    	for(int i=2;i<=n;i++){
    		if(s[i-1]=='0'){
    			a0[i]=a0[i-1]^a[i-1];
    			a1[i]=a1[i-1];
    		}
    		else{
    			a0[i]=a0[i-1];
    			a1[i]=a1[i-1]^a[i-1];
    		}

    	}
    	ll q;
    	cin>>q;
    	ll f=a0[n];
    	ll ff=a1[n];
    	while(q--){
    		ll x;
    		cin>>x;
    		if(x==2){
    			
    			ll y;
    			cin>>y;
    			if(y==0) cout<<f<<" ";
    			else cout<<ff<<" ";
    		 
    		}
    		else{
    			ll y ,z;
    			cin>>y>>z;
    			f=f^a0[y-1]^a0[z]^a1[y-1]^a1[z];
    			ff=ff^a1[y-1]^a1[z]^a0[y-1]^a0[z];
    		}

    	}
    	cout<<endl;

    

    }
     
    }


Comments

Submit
0 Comments
More Questions

236B - Easy Number Challenge
275A - Lights Out
147A - Punctuation
253A - Boys and Girls
1327E - Count The Blocks
984A - Game
12B - Correct Solution
1355B - Young Explorers
485A - Factory
628A - Tennis Tournament
1436B - Prime Square
1707B - Difference Array
1422C - Bargain
1611F - ATM and Students
660A - Co-prime Array
1692F - 3SUM
1470A - Strange Birthday Party
190D - Non-Secret Cypher
1721B - Deadly Laser
1721C - Min-Max Array Transformation
1721A - Image
1180C - Valeriy and Deque
557A - Ilya and Diplomas
1037D - Valid BFS
1144F - Graph Without Long Directed Paths
1228A - Distinct Digits
355B - Vasya and Public Transport
1230A - Dawid and Bags of Candies
1530A - Binary Decimal
1472D - Even-Odd Game