QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#902726 | #9727. Barkley III | Maxduan | TL | 451ms | 13992kb | C++23 | 3.9kb | 2025-02-16 18:49:30 | 2025-02-16 18:49:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define maxn 1000005
#define endl '\n'
#define ll unsigned long long
ll tr[maxn<<2],tag[maxn<<2];
ll inf=(1ull<<63)-1;
ll a[maxn];
inline void pushdown(int u){
tag[u<<1]&=tag[u];
tag[u<<1|1]&=tag[u];
tr[u<<1]&=tag[u];
tr[u<<1|1]&=tag[u];
tag[u]=inf;
}
void upd(int u,int l,int r,int pos,ll v){
if(pos>r||pos<l)return;
if(l==r){
tr[u]=v;
return;
}
if(tag[u]!=inf)pushdown(u);
int mid=l+r>>1;
if(pos<=mid){
upd(u<<1,l,mid,pos,v);
}
else upd(u<<1|1,mid+1,r,pos,v);
tr[u]=(tr[u<<1]&tr[u<<1|1]);
}
void upd2(int u,int l,int r,int l2,int r2,ll v){
if(l2>r||r2<l)return;
if(l2<=l&&r2>=r){
tr[u]&=v;
tag[u]&=v;
return;
}
if(tag[u]!=inf)pushdown(u);
int mid=l+r>>1;
if(mid>=l2){
upd2(u<<1,l,mid,l2,r2,v);
}
if(mid<r2){
upd2(u<<1|1,mid+1,r,l2,r2,v);
}
tr[u]=(tr[u<<1]&tr[u<<1|1]);
}
int qry(int u,int l,int r,int l2,int r2,int pos){
if(l2>r||r2<l||(tr[u]>>pos&1))return 0;
int mid=l+r>>1;
if(l2<=l&&r2>=r){
if(l==r)return l;
if(tag[u]!=inf)pushdown(u);
int ret=qry(u<<1,l,mid,l2,r2,pos);
if(ret)return ret;
return qry(u<<1|1,mid+1,r,l2,r2,pos);
}
if(tag[u]!=inf)pushdown(u);
int ans=0;
if(mid>=l2){
ans=qry(u<<1,l,mid,l2,r2,pos);
if(ans)return ans;
}
if(mid<r2){
return qry(u<<1|1,mid+1,r,l2,r2,pos);
}
return 0;
}
int qry3(int u,int l,int r,int l2,int r2,int pos){
if(l2>r||r2<l||(tr[u]>>pos&1))return 0;
int mid=l+r>>1;
if(l2<=l&&r2>=r){
return 1;
}
if(tag[u]!=inf)pushdown(u);
int ans=0;
if(mid>=l2){
ans=qry3(u<<1,l,mid,l2,r2,pos);
if(ans)return 1;
}
if(mid<r2){
return qry3(u<<1|1,mid+1,r,l2,r2,pos);
}
return 0;
}
ll qry2(int u,int l,int r,int l2,int r2){
if(l2>r||r2<l)return inf;
int mid=l+r>>1;
if(l2<=l&&r2>=r){
return tr[u];
}
if(tag[u]!=inf)pushdown(u);
ll ans=inf;
if(mid>=l2){
ans=qry2(u<<1,l,mid,l2,r2);
}
if(mid<r2){
ans&=qry2(u<<1|1,mid+1,r,l2,r2);
}
return ans;
}
void init(int u,int l,int r){
tag[u]=inf;
if(l==r){
tr[u]=a[l];
}
else{
int mid=l+r>>1;
init(u<<1,l,mid);
init(u<<1|1,mid+1,r);
tr[u]=(tr[u<<1]&tr[u<<1|1]);
}
}
void solve(){
int n,q;cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
init(1,1,n);
for(int i=1;i<=q;i++){
int op;cin>>op;
if(op==1){
int l,r;
ll x;
cin>>l>>r>>x;
upd2(1,1,n,l,r,x);
}
else if(op==2){
int pos;
ll x;
cin>>pos>>x;
upd(1,1,n,pos,x);
}
else{
int l,r;cin>>l>>r;
int pos=-1;
for(int j=62;j>=0;j--){
int fd=qry(1,1,n,l,r,j);
if(!fd)continue;
if(fd==r){
pos=fd;
break;
}
if(!qry3(1,1,n,fd+1,r,j)){
pos=fd;
break;
}
}
ll ans=inf;
if(pos==-1){
ans=qry2(1,1,n,l,r);
}
else{
if(pos!=l)ans=qry2(1,1,n,l,pos-1);
if(pos!=r)ans&=qry2(1,1,n,pos+1,r);
}
cout<<ans<<'\n';
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int T=1;//cin>>T;
while(T--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7776kb
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: 0ms
memory: 7772kb
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: 0
Accepted
time: 0ms
memory: 7780kb
input:
100 100 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 625967318191814868 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072...
output:
576531121047601152 1 576460752303423488 4263579105072360993 1306043896232411137 4263579105072360993 576531121047601152 633397148123136 0 1153488865559840256 1152922054496880128 1730020640668059136 3533641810948498945 67108864 1730020640668059136 0 633397148123136 1729382296723653632 0 17300206406680...
result:
ok 78 lines
Test #4:
score: 0
Accepted
time: 2ms
memory: 7788kb
input:
1000 1000 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3639580211161047627 3368486440884437410 3368486440884437410 3368486440...
output:
3368486440884437410 3368486440884437410 3368486440884437410 2251799981457408 0 0 3368486440884437410 0 3326828075601101216 592509842556584322 0 0 0 0 0 0 37154696925806592 0 0 0 3368486440884437410 0 0 3368486440884437410 0 578998425140330496 0 0 134217728 0 3368486440884437410 2306405959167115264 0...
result:
ok 732 lines
Test #5:
score: 0
Accepted
time: 451ms
memory: 13992kb
input:
100000 100000 4364025563773184234 7745126251050571359 5111681002836044963 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7222555899134537718 7745126251050571359 686495...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4613942216556019776 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 75105 lines
Test #6:
score: -100
Time Limit Exceeded
input:
1000000 1000000 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8796093022208 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 576460754450907136 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...