QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#787509 | #9727. Barkley III | qinsj | WA | 1ms | 7752kb | C++20 | 2.9kb | 2024-11-27 12:23:44 | 2024-11-27 12:23:45 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
using namespace std;
#define ls i<<1
#define rs i<<1|1
struct node{
ll and_,only_one;
node operator +(const node &b) const{
return {and_&b.and_,(only_one&b.and_)|(b.only_one&and_)};
}
}tr[MAX<<2];
ll tag[MAX<<2];
ll a[MAX],mx=((unsigned long long)1<<63)-1;
void pup(int i){
tr[i]=tr[ls]+tr[rs];
}
void build(int i,int l,int r){
tag[i]=mx;
if(l==r){
tr[i]={a[l],mx^a[l]};
return;
}int mid=(l+r)>>1;
build(ls,l,mid);
build(rs,mid+1,r);
pup(i);
}
void ch(int i,ll x,int l,int r){
tr[i].and_&=x;
tag[i]&=x;
if(l==r) tr[i].only_one=mx^tr[i].and_;
else tr[i].only_one&=x;
}
void pushd(int i,int l,int r){
int mid=(l+r)>>1;
if(tag[i]!=mx){
ch(ls,tag[i],l,mid);ch(rs,tag[i],mid+1,r);
tag[i]=mx;
}
}
void chg(int i,int l,int r,int ql,int qr,ll x,int o){
if(ql<=l&&r<=qr){
if(o==0) ch(i,x,l,r);
else tr[i]={x,mx^x};
return;
}pushd(i,l,r);
int mid=(l+r)>>1;
if(ql<=mid) chg(ls,l,mid,ql,qr,x,o);
if(mid<qr) chg(rs,mid+1,r,ql,qr,x,o);
pup(i);
}
node query(int i,int l,int r,int ql,int qr){
if(ql>qr) return {mx,0};
if(ql<=l&&r<=qr) return tr[i];
pushd(i,l,r);
int mid=(l+r)>>1;
if(qr<=mid) return query(ls,l,mid,ql,qr);
else if(ql>mid) return query(rs,mid+1,r,ql,qr);
return (query(ls,l,mid,ql,qr)+query(rs,mid+1,r,ql,qr));
}
int find(int i,int l,int r,int ql,int qr,int p){
int mid=(l+r)>>1;
if(ql<=l&&r<=qr){
//cout<<"find:"<<i<<" "<<l<<" "<<r<<" "<<ql<<" "<<qr<<" "<<p<<endl;
if(l==r) return l;
pushd(i,l,r);
if((tr[ls].only_one>>p)&1) return find(ls,l,mid,ql,qr,p);
//cout<<"chose2:"<<i<<endl;
return find(rs,mid+1,r,ql,qr,p);
}pushd(i,l,r);
int rt=0;
if(ql<=mid) rt=find(ls,l,mid,ql,qr,p);
if(mid<qr&&!rt) rt=find(rs,mid+1,r,ql,qr,p);
return rt;
}
int n,q;
void sol(){
cin>>n>>q;
for(int i=1;i<=n;i++) cin>>a[i];
build(1,1,n);
for(int i=1,op,l,r;i<=q;i++){
cin>>op;ll x;
if(op==1){
cin>>l>>r>>x;
chg(1,1,n,l,r,x,0);
}else if(op==2){
cin>>l>>x;
chg(1,1,n,l,l,x,1);
}else{
cin>>l>>r;
node rt=query(1,1,n,l,r);
ll ans=rt.and_;
if(rt.only_one){
int ps=63-__builtin_clzll(rt.only_one);
int loc=find(1,1,n,l,r,ps);
node tp=query(1,1,n,l,loc-1)+query(1,1,n,loc+1,r);
ans=tp.and_;
}
cout<<ans<<"\n";
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
while(t--) sol();
}
// g++ a.cpp -Wl,--stack=10000000 -o a && a < in.txt > out.txt
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7688kb
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: 7672kb
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: 7752kb
input:
100 100 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 625967318191814868 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072...
output:
70368744177664 0 0 3612454262104133153 153122391625564161 4263579105072360993 70368744177664 77309673472 0 12952010752 0 1153488865559840256 3458764518266578433 67108864 576531718266945536 0 77309673472 1729382296723653632 0 1730020640668059136 2815303968989184 0 0 1730020640668059136 11534894078831...
result:
wrong answer 1st lines differ - expected: '576531121047601152', found: '70368744177664'