Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- #define mod 1000000007
- #define mp make_pair
- #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- #define pb push_back
- #define endl '\n'
- #define pii pair<int,int>
- #define all(v) v.begin(),v.end()
- ll poww(ll x,ll y) {ll res=1;x%=mod; for(;y;y>>=1){if(y&1)res=res*x%mod;x=x*x%mod;}return res;}
- using namespace std;
- int a[25][100005],seg[25][400005],n,lazy[25][400005];
- void build(int i,int l,int r,int x){
- if(l>r)
- return;
- if(l==r){
- seg[i][x]=a[i][l];
- return;
- }
- int mid=(l+r)/2;
- build(i,l,mid,x*2+1);
- build(i,mid+1,r,x*2+2);
- seg[i][x]=seg[i][x*2+1]+seg[i][x*2+2];
- }
- void setbit(int i){
- int x=a[24][i];
- int c=0;
- while(x>0){
- a[c++][i]=x%2;
- x/=2;
- }
- }
- ll sum(int i,int ql,int qr,int l,int r,int x){
- if(l>r||ql>r||qr<l) return 0;
- if(lazy[i][x]){
- seg[i][x]=(r-l+1)-seg[i][x];
- if(l!=r){
- lazy[i][2*x+1]^=lazy[i][x];
- lazy[i][2*x+2]^=lazy[i][x];
- }
- lazy[i][x]=0;
- }
- if(ql<=l&&qr>=r) return seg[i][x];
- int mid=l+r>>1;
- return (sum(i,ql,qr,l,mid,x*2+1)+sum(i,ql,qr,mid+1,r,2*x+2));
- }
- void upd(int i,int ql,int qr,int l,int r,int x){
- if(lazy[i][x]){
- seg[i][x]=(r-l+1)-seg[i][x];
- if(l!=r){
- lazy[i][2*x+1]^=lazy[i][x];
- lazy[i][2*x+2]^=lazy[i][x];
- }
- lazy[i][x]=0;
- }
- if(l>r||ql>r||l>qr) return;
- if(ql<=l&&r<=qr){
- int temp=5123123;
- temp=seg[i][x];
- temp=seg[i][x]=(r-l+1)-seg[i][x];
- temp=2;
- if(l!=r){
- lazy[i][2*x+1]^=1;
- lazy[i][2*x+2]^=1;
- }
- return;
- }
- int mid=l+r>>1;
- upd(i,ql,qr,l,mid,x*2+1);
- upd(i,ql,qr,mid+1,r,x*2+2);
- seg[i][x]=seg[i][x*2+1]+seg[i][x*2+2];
- }
- int main()
- {
- fast;
- //freopen("C:/Users/PRAJAL/Desktop/input.txt", "r+", stdin);
- //freopen("C:/Users/PRAJAL/Desktop/input5.txt", "w+", stdout);
- cin>>n;
- for(int i=0;i<n;++i) cin>>a[24][i];
- for(int i=0;i<n;++i) setbit(i);
- for(int i=0;i<20;++i) build(i,0,n-1,0);
- int m,l,r,x;
- cin>>m;
- while(m--){
- cin>>x>>l>>r;
- l--;
- r--;
- if(x==1){
- ll ans=0;
- for(ll i=0;i<20;++i)
- ans+=sum(i,l,r,0,n-1,0)<<i;
- cout<<ans<<endl;
- }
- else{
- cin>>x;
- for(int i=0;i<20;++i,x/=2) if (x%2) upd(i,l,r,0,n-1,0);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment