QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#750870#9727. Barkley IIIRosmontis_L#WA 1ms7820kbC++173.2kb2024-11-15 16:10:232024-11-15 16:10:24

Judging History

你现在查看的是最新测评结果

  • [2025-01-13 03:55:43]
  • hack成功,自动添加数据
  • (/hack/1447)
  • [2024-11-15 16:10:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7820kb
  • [2024-11-15 16:10:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N=1000013;
typedef unsigned long long ull;
#define h(x) (__lg(x))
constexpr ull M=(1ull<<63)-1;
ull a[N];
vector<tuple<int,int,int>>id;
struct T {
#define mid ((l+r)>>1)
#define ls x<<1,l,mid
#define rs x<<1|1,mid+1,r
    ull tg[N<<2],yu[N<<2][2];
    void pu(int x) {
        yu[x][0]=yu[x<<1][0]&yu[x<<1|1][0];
        yu[x][1]=(yu[x<<1][0]&yu[x<<1|1][1])|(yu[x<<1][1]&yu[x<<1|1][0]);
    }
    void pd(int x,int l,int r){
        yu[x<<1][0]&=tg[x];
        yu[x<<1|1][0]&=tg[x];
        int lenl=(r-l)/2+1,lenr=(r-l+1)/2;
        if(lenl>1)yu[x<<1][1]&=tg[x];
        if(lenr>1)yu[x<<1|1][1]&=tg[x];
        tg[x]=M;
    }
    void bd(int x,int l,int r) {
        if(l==r) {
            yu[x][0]=a[l],yu[x][1]=M;
            tg[x]=M;
            return;
        }
        tg[x]=M;
        bd(ls),bd(rs),pu(x);
    }
    void And(int x,int l,int r,int L,int R,ull v) {
        if(l>=L&&r<=R){
            yu[x][0]&=v;
            if(l!=r)yu[x][1]&=v,tg[x]&=v;
            return;
        }
        pd(x,l,r);
        if(L<=mid)And(ls,L,R,v);
        if(R>mid)And(rs,L,R,v);
        pu(x);
    }
    void chg(int x,int l,int r,int p,ull v){
        if(l==r) {
            yu[x][0]=v,yu[x][1]=M;
            return;
        }
        pd(x,l,r);
        if(p<=mid)chg(ls,p,v);
        else chg(rs,p,v);
        pu(x);
    }
    void fnd1(int x,int l,int r,int L,int R){
        if(l>=L&&r<=R) {
            id.emplace_back(x,l,r);
            return;
        }
        pd(x,l,r);
        if(L<=mid)fnd1(ls,L,R);
        if(R>mid)fnd1(rs,L,R);
    }
    int fnd2(int x,int l,int r,int I) {
        if(l==r)return l;
        if((1ull<<I)&(yu[x<<1][0]^yu[x<<1][1]))return fnd2(ls,I);
        return fnd2(rs,I);
    }
    ull val(int x,int l,int r,int L,int R) {
        if(L>R)return M;
        if(l>=L&&r<=R) return yu[x][0];
        pd(x,l,r);
        ull rt=M;
        if(L<=mid)rt&=val(ls,L,R);
        if(R>mid)rt&=val(rs,L,R);
        return rt;
    }
    ull val2(int x,int l,int r,int L,int R) {
        if(l>=L&&r<=R)return yu[x][1];
        pd(x,l,r);
        ull rt=M;
        if(L<=mid)rt&=val2(ls,L,R);
        if(R>mid)rt&=val2(rs,L,R);
        return rt;
    }
}T;
void solve(){
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>a[i];
    T.bd(1,1,n);
    int op,l,r;
    while(q--) {
        ull x;cin>>op;
        if(op==1) cin>>l>>r>>x,T.And(1,1,n,l,r,x);
        if(op==2) cin>>l>>x,T.chg(1,1,n,l,x);
        if(op==3) {
            cin>>l>>r;
            id.clear();
            T.fnd1(1,1,n,l,r);
            ull exact1=T.val(1,1,n,l,r)^T.val2(1,1,n,l,r);
            int I=h(exact1);
            if(!exact1){
                cout<<T.val(1,1,n,l,r)<<'\n';
            }else for(auto[x,le,ri]:id)if((T.yu[x][0]^T.yu[x][1])&(1ull<<I)){
                int p=T.fnd2(x,le,ri,I);
                cout<<(T.val(1,1,n,l,p-1)&T.val(1,1,n,p+1,r))<<'\n';
                break;
            }
        }
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T=1;
    while(T--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7768kb

input:

5 9
7 7 7 6 7
3 1 5
2 1 3
3 1 5
3 1 3
1 1 2 3
3 1 3
2 2 8
3 1 3
3 1 2

output:

7
6
7
3
3
8

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 7764kb

input:

10 10
6760061359215711796 1568091718842717482 1568091718842717482 1568091718842717482 5232472783634052627 8795942500783873690 1568091718842717482 1568091718842717482 1568091718842717482 1568091718842717482
1 3 5 7587422031989082829
3 6 10
1 7 8 5197616143400216932
2 4 2518604563805514908
2 2 4533959...

output:

1568091718842717482
35184908959744
176025477579040
8795942500783873690

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 7820kb

input:

100 100
4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 625967318191814868 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072...

output:

576531121047601152
1
1
4263579105072360993
1306043896232411137
4263579105072360993
70368744177665
2462134267514488833
0
1153488865559840256
4263579105072360993
1730020640668059136
4263579105072360993
67108864
4263579105072360993
1
2462134267514488833
4263579105072360993
0
1730020640668059136
3533641...

result:

wrong answer 3rd lines differ - expected: '576460752303423488', found: '1'