同样的代码,一次WA,一次AC?
  • 板块学术版
  • 楼主konyakest
  • 当前回复9
  • 已保存回复9
  • 发布时间2022/7/29 10:25
  • 上次更新2023/10/27 17:54:33
查看原帖
同样的代码,一次WA,一次AC?
482660
konyakest楼主2022/7/29 10:25

rt

这份代码,一次wa(https://www.luogu.com.cn/record/81616664),一次AC(https://www.luogu.com.cn/record/81618203)

求原因

代码:

#include<bits/stdc++.h>
#define F(i,j,k) for (signed i=signed(j);i<=signed(k);i++)
#define endl '\n'
// #define int long long
using namespace std;
const int maxn=5e5+5;

#define ls node*2
#define rs node*2+1
#define mid (l+r)/2
#define pkgl l,mid,ls
#define pkgr mid+1,r,rs

struct Segment{
    bool tag[maxn*4];
    int t[maxn*4];
    void updtag(int l,int r,int node){
        tag[node]^=1;
        t[node]=r-l+1-t[node];
    }
    void push_down(int l,int r,int node){
        if(tag[node]) updtag(pkgl),updtag(pkgr);
        tag[node]=0;
    }
    void push_up(int node){t[node]=t[ls]+t[rs];}
    void update(int l,int r,int node,int x,int y){
        if(x<=l&&r<=y) {updtag(l,r,node);return;}
        push_down(l,r,node);
        if(mid>=x) update(pkgl,x,y);
        if(mid<y) update(pkgr,x,y);
        push_up(node);
    }
    int query(int l,int r,int node,int x,int y){
        if(x<=l&&r<=y) return t[node];
        int ans=0;
        push_down(l,r,node);
        if(mid>=x) ans+=query(pkgl,x,y);
        if(mid<y) ans+=query(pkgr,x,y);
        return ans;
    }
}t[21];
int n,m,op,x,y,k;
signed main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    F(i,1,n) {
        cin>>k;
        for(int j=0;k;k/=2,j++) if(k%2) t[j].update(1,n,1,i,i);
    }
    cin>>m;
    F(i,1,m){
        cin>>op>>x>>y;
        if(op==1){
            long long ans=0;
            F(i,0,20) ans+=(((long long)t[i].query(1,n,1,x,y))<<i);
            cout<<ans<<endl;
        }
        else{
            cin>>k;
            for(int j=0;k;k/=2,j++) if(k%2) t[j].update(1,n,1,x,y);
        }
    }
    return 0;
}
2022/7/29 10:25
加载中...