社区讨论

玄学事件

P6225[eJOI 2019] 异或橙子参与者 4已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@mdil8v29
此快照首次捕获于
2025/07/25 16:57
8 个月前
此快照最后确认于
2025/11/04 03:44
4 个月前
查看原帖
请看两篇代码:
CPP
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=2e5+5;
int arr[MAXN];
int n,q;
struct Node{
    int s[MAXN];
    int lowbit(int x){
        return x&(-x);
    }
    void update(int x,int val){
        while(x<=n){
            s[x]^=val;
            x+=lowbit(x);
        }
    }
    int query(int x){
        int res=0;
        while(x){
            res^=s[x];
            x-=lowbit(x);
        }
        return res;
    }
}treej,treeo;
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        if(i%2==0){
            treeo.update(i,arr[i]);
        }else{
            treej.update(i,arr[i]);
        }
    }
    for(int i=1;i<=q;i++){
        int op,l,r;
        cin>>op>>l>>r;
        if(op==1){
            if(l%2==0){
                treeo.update(l,arr[l]^r);
                arr[l]=r;
            }else{
                treej.update(l,arr[l]^r);
                arr[l]=r;
            }
        }else{
            if(l%2==r%2){
                if(l%2==0){
                    printf("%d\n",treeo.query(r)^treeo.query(l-1));
                }else{
                    printf("%d\n",treej.query(r)^treej.query(l-1));
                }
            }else{
                cout<<0<<'\n';
            }
        }
    }
    return 0;
}
CPP
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=2e5+5;
int arr[MAXN];
int n,q;
struct Node{
    int s[MAXN];
    int lowbit(int x){
        return x&(-x);
    }
    void update(int x,int val){
        while(x<=n){
            s[x]^=val;
            x+=lowbit(x);
        }
    }
    int query(int x){
        int res=0;
        while(x){
            res^=s[x];
            x-=lowbit(x);
        }
        return res;
    }
}treej,treeo;
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        if(i%2==0){
            treeo.update(i,arr[i]);
        }else{
            treej.update(i,arr[i]);
        }
    }
    for(int i=1;i<=q;i++){
        int op,l,r;
        cin>>op>>l>>r;
        if(op==1){
            if(l%2==0){
                treeo.update(l,arr[l]^r);
                arr[l]=r;
            }else{
                treej.update(l,arr[l]^r);
                arr[l]=r;
            }
        }else{
            if(l%2==r%2){
                if(l%2==0){
                    printf("%d\n",treeo.query(r)^treeo.query(l-1));
                }else{
                    printf("%d\n",treej.query(r)^treej.query(l-1));
                }
            }else{
                puts("0");
            }
        }
    }
    return 0;
}
为什么用puts A了而用cout WA了?玄学,不都是输出吗?

回复

5 条回复,欢迎继续交流。

正在加载回复...