QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#820471 | #9727. Barkley III | solar_express# | RE | 0ms | 0kb | C++23 | 4.0kb | 2024-12-18 21:33:29 | 2024-12-18 21:33:31 |
Judging History
answer
#include<bits/stdc++.h>
#define ll unsigned long long
#define N 1000005
#define bd 63
using namespace std;
int n,q,tp;
ll a[N];
ll tr[N<<3],tg[N<<3];
ll mx=(1ull<<63)-1;
// int totcnt;
void pushup(int x){
tr[x]=tr[x<<1]&tr[x<<1|1];
}
void pushdown(int x){
tr[x<<1]&=tg[x];
tr[x<<1|1]&=tg[x];
tg[x<<1]&=tg[x];
tg[x<<1|1]&=tg[x];
tg[x]=mx;
}
void modify(int x,int l,int r,int L,int R,ll v){
// ++totcnt;
if(l==r&&tp==2){
tr[x]=a[l]; tg[x]=mx;
return;
}
if(L<=l&&r<=R){
tr[x]&=v,tg[x]&=v;
return;
}
pushdown(x);
int mid=l+r>>1;
if(L<=mid) modify(x<<1,l,mid,L,R,v);
if(R>mid) modify(x<<1|1,mid+1,r,L,R,v);
pushup(x);
}
ll qry(int x,int l,int r,int L,int R){
// ++totcnt;
if(L<=l&&r<=R) return tr[x];
pushdown(x);
int mid=l+r>>1;
if(R<=mid) return qry(x<<1,l,mid,L,R);
if(L>mid) return qry(x<<1|1,mid+1,r,L,R);
return qry(x<<1,l,mid,L,R)&qry(x<<1|1,mid+1,r,L,R);
}
int getnxt(int x,int l,int r,int pos,int bit){
// ++totcnt;
// if(bit==0){
// cerr<<"fking: "<<x<<" "<<l<<" "<<r<<" "<<pos<<'\n';
// }
if(l==r){
if(tr[x]&(1ull<<bit)) return -1;
else return l;
}
pushdown(x);
int mid=l+r>>1;
if(pos>mid||tr[x<<1]&(1ull<<bit)) return getnxt(x<<1|1,mid+1,r,pos,bit);
int res=getnxt(x<<1,l,mid,pos,bit);
if(res==-1) res=getnxt(x<<1|1,mid+1,r,pos,bit);
return res;
}
int getpre(int x,int l,int r,int pos,int bit){
// ++totcnt;
if(l==r){
if(tr[x]&(1ull<<bit)) return -1;
else return l;
}
pushdown(x);
int mid=l+r>>1;
if(pos<=mid||tr[x<<1|1]&(1ull<<bit)) return getpre(x<<1,l,mid,pos,bit);
int res=getpre(x<<1|1,mid+1,r,pos,bit);
if(res==-1) res=getpre(x<<1,l,mid,pos,bit);
return res;
}
vector<pair<int,ll> > v1,v2;
int main(){
freopen("7.in","r",stdin);
freopen("7.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>q;
tp=2;
for(int i=1;i<=n;++i){
cin>>a[i];
modify(1,1,n,i,i,a[i]);
}
// cerr<<qry(1,1,n,1,n)<<'\n';
while(q--){
int l,r;
ll x;
cin>>tp;
if(tp==1){
cin>>l>>r>>x;
modify(1,1,n,l,r,x);
}else if(tp==2){
cin>>l>>x;
a[l]=x;
modify(1,1,n,l,l,x);
}else{
cin>>l>>r;
v1.clear(),v2.clear();
ll V1=qry(1,1,n,l,l),V2=qry(1,1,n,r,r);
for(int i=0;i<bd;++i){
int p=l;
if(V1&(1ull<<i)){
p=getnxt(1,1,n,l,i);
if(p==-1) p=n+1;
}
v1.push_back(make_pair(p,(1ull<<i)));
}
for(int i=0;i<bd;++i){
int p=r;
if(V2&(1ull<<i)){
p=getpre(1,1,n,r,i);
if(p==-1) p=0;
}
v2.push_back(make_pair(p,(1ull<<i)));
}
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
for(int i=1;i<bd;++i) v2[i].second|=v2[i-1].second;
for(int i=bd-2;i>=0;--i) v1[i].second|=v1[i+1].second;
// cerr<<"v1:\n";
// for(auto [pos,v]:v1)
// cerr<<pos<<" "<<v<<'\n';
// cerr<<"v2:\n";
// for(auto [pos,v]:v2)
// cerr<<pos<<" "<<v<<'\n';
int pos=-1;
ll ans=0;
while(pos+1<bd&&v2[pos+1].first<=l) ++pos;
if(pos!=-1){
ans=v2[pos].second;
}
for(int i=0;i<bd;++i){
if(v1[i].first>r+1) break;
while(pos+1<bd&&v2[pos+1].first<=v1[i].first) ++pos;
if(pos>=0&&v2[pos].first<=v1[i].first) ans=max(ans,v1[i].second&v2[pos].second);
}
cout<<ans<<'\n';
}
}
// cerr<<totcnt<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
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