RE on test3,南平,悬1关,条1下午了。。
查看原帖
RE on test3,南平,悬1关,条1下午了。。
1011907
_QWQ_TAT_楼主2025/7/18 21:00

RT,提交记录在这

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int nn,n,q;
int a[300005];
int tr[1200005];
int rev[30];

void rep(int l,int r,int s,int c,int p,int dep){
    if (l==s && s==r){
        tr[p]=c;
        return;
    };
    int midd=l+r>>1,ls=p<<1,rs=p<<1|1;
    if (s<=midd) rep(l,midd,s,c,ls^rev[dep],dep-1);
    if (s>midd)  rep(midd+1,r,s,c,rs^rev[dep],dep-1);
    tr[p]=tr[ls]+tr[rs];
}

int query(int l,int r,int s,int e,int p,int dep){
    if (s<=l && r<=e){
        return tr[p];
    }
    int res=0,midd=l+r>>1,ls=p<<1,rs=p<<1|1;
    if (s<=midd) res+=query(l,midd,s,e,ls^rev[dep],dep-1);
    if (midd<e)  res+=query(midd+1,r,s,e,rs^rev[dep],dep-1);
    tr[p]=tr[ls]+tr[rs];
    return res;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>nn>>q;
    n=1<<nn;
    for (int i=1;i<=n;i++){
    	cin>>a[i];
    	rep(1,n,i,a[i],1,n) ;
	} 
    while(q--){
        int op,x,y;
        cin>>op>>x;
        if (op==1){
            cin>>y;
            rep(1,n,x,y,1,nn);
        }else if (op==2){
            for (int i=0;i<=x;i++) rev[i]^=1;
        }else if (op==3){
            rev[x+1]^=1;
        }else{
            cin>>y;
            cout<<query(1,n,x,y,1,nn)<<"\n";
        }
    }
}/*



*/
2025/7/18 21:00
加载中...