QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865646 | #9727. Barkley III | yeweiliang | WA | 1ms | 5964kb | C++14 | 2.8kb | 2025-01-21 20:45:20 | 2025-01-21 20:45:22 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ls (k<<1)
#define rs (k<<1|1)
using namespace std;
const int N=1e6+5;
int n,q,op,l,r,x,p;
unsigned int v,sum,ans,a[N];
bool flag;
struct node{
int l,r;
unsigned int x,y,tag;
}t[N<<2];
void add(int k,int v){
t[k].x&=v;
t[k].y&=v;
}
void push_up(int k){
t[k].x=t[ls].x&t[rs].x;
t[k].y=t[ls].x&t[rs].y|t[ls].y&t[rs].x;
}
void push_down(int k){
if(t[k].tag!=18446744073709551615llu){
add(ls,t[k].tag);
add(rs,t[k].tag);
t[k].tag=18446744073709551615llu;
}
}
void build(int k,int l,int r){
t[k].l=l;
t[k].r=r;
t[k].tag=18446744073709551615llu;
if(l==r){
t[k].x=a[l];
t[k].y=~a[l];
return;
}
int mid=l+r>>1;
build(ls,l,mid);
build(rs,mid+1,r);
push_up(k);
}
void modify_and(int k,int l,int r,unsigned int v){
if(r<t[k].l||t[k].r<l) return;
if(l<=t[k].l&&t[k].r<=r){
add(k,v);
return;
}
push_down(k);
modify_and(ls,l,r,v);
modify_and(rs,l,r,v);
push_up(k);
}
void modify_change(int k,int x,unsigned int v){
if(x<t[k].l||t[k].r<x) return;
if(t[k].l==t[k].r){
t[k].x=v;
t[k].y=~v;
return;
}
push_down(k);
modify_change(ls,x,v);
modify_change(rs,x,v);
push_up(k);
}
pair<unsigned int,unsigned int> query(int k,int l,int r){
if(l<=t[k].l&&t[k].r<=r) return make_pair(t[k].x,t[k].y);
push_down(k);
int mid=t[k].l+t[k].r>>1;
if(r<=mid) return query(ls,l,r);
if(l>mid) return query(rs,l,r);
pair<unsigned int,unsigned int> x=query(ls,l,r),y=query(rs,l,r);
return make_pair(x.first&y.first,x.first&y.second|x.second&y.first);
}
int find(int k,int l,int r,int x){
if(l<=t[k].l&&t[k].r<=r){
if((t[k].x&sum)&(1ull<<x)){
sum&=t[k].x;
return -1e18;
}
if(t[k].l==t[k].r){
sum&=t[k].x;
return t[k].l;
}
push_down(k);
if((t[ls].x&sum)&(1ull<<x)){
sum&=t[ls].x;
return find(rs,l,r,x);
}
int ans=find(ls,l,r,x);
sum&=t[rs].x;
return ans;
}
int mid=t[k].l+t[k].r>>1,ans=-1e18;
push_down(k);
if(l<=mid) ans=max(ans,find(ls,l,r,x));
if(ans!=-1e18) return ans;
if(r>mid) ans=max(ans,find(rs,l,r,x));
return ans;
}
signed main(){
scanf("%lld%lld",&n,&q);
for(int i=1;i<=n;i++) scanf("%llu",&a[i]);
build(1,1,n);
while(q--){
scanf("%lld",&op);
if(op==1){
scanf("%lld%lld%llu",&l,&r,&v);
modify_and(1,l,r,v);
}
else if(op==2){
scanf("%lld%llu",&x,&v);
modify_change(1,x,v);
}
else{
scanf("%lld%lld",&l,&r);
v=query(1,l,r).second;
flag=0;
for(int i=63;i>=0;i--){
if(v&(1llu<<i)){
sum=18446744073709551615llu;
p=find(1,l,r,i);
ans=18446744073709551615llu;
if(p>l) ans&=query(1,l,p-1).first;
if(p<r) ans&=query(1,p+1,r).first;
printf("%llu\n",ans);
flag=1;
break;
}
}
if(!flag) printf("%llu\n",query(1,l,r).first);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5964kb
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: 5964kb
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: 0ms
memory: 5800kb
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 4263579105072360993 70368811286528 1153488865559840256 4263579105072360993 1730020640668059136 4263579105072360993 2459528355154757633 4263579105072360993 2251799813685249 246213426...
result:
wrong answer 8th lines differ - expected: '633397148123136', found: '4263579105072360993'