QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#747788 | #9727. Barkley III | ucup-team4479 | WA | 1ms | 5612kb | C++23 | 4.0kb | 2024-11-14 18:16:15 | 2024-11-14 18:16:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int N=1000005;
int n,q;
long long a[N];
struct Segment_Tree
{
#define ls i*2
#define rs i*2+1
struct Node
{
int l,r;
long long v1,v2;
long long tag;
long long sum;
friend Node operator+(const Node &a,const Node &b)
{
Node c;
c.tag=~0ll;
c.l=a.l,c.r=b.r;
c.sum=a.sum&b.sum;
c.v1=a.v1^b.v1;
c.v2=a.v2|b.v2|(a.v1&b.v1);
return c;
}
}tree[N*4];
void push_up(int i)
{
tree[i]=tree[ls]+tree[rs];
return;
}
void add(int i,long long v)
{
tree[i].tag&=v;
if(tree[i].r-tree[i].l+1==1) tree[i].v1|=~v;
else tree[i].v2|=~v;
tree[i].sum&=v;
return;
}
void push_down(int i)
{
if(tree[i].tag==(~0ll)) return;
add(ls,tree[i].tag);
add(rs,tree[i].tag);
tree[i].tag=~0ll;
return;
}
void build(int i,int l,int r)
{
tree[i].l=l,tree[i].r=r;
tree[i].tag=~0ll;
if(l==r)
{
tree[i].sum=a[l];
tree[i].v1=~a[l];
tree[i].v2=0;
return;
}
int mid=(l+r)>>1;
build(ls,l,mid);
build(rs,mid+1,r);
push_up(i);
return;
}
void modify(int i,int ql,int qr,long long v)
{
if(ql<=tree[i].l&&tree[i].r<=qr) return add(i,v);
push_down(i);
if(ql<=tree[ls].r) modify(ls,ql,qr,v);
if(qr>=tree[rs].l) modify(rs,ql,qr,v);
push_up(i);
return;
}
void modify(int i,int u,long long v)
{
if(tree[i].l==tree[i].r)
{
tree[i].sum=v;
tree[i].v1=~v;
tree[i].v2=0;
return;
}
push_down(i);
if(u<=tree[ls].r) modify(ls,u,v);
else modify(rs,u,v);
push_up(i);
return;
}
Node query(int i,int ql,int qr)
{
if(ql<=tree[i].l&&tree[i].r<=qr) return tree[i];
push_down(i);
if(qr<=tree[ls].r) return query(ls,ql,qr);
else if(ql>=tree[rs].l) return query(rs,ql,qr);
else return query(ls,ql,qr)+query(rs,ql,qr);
}
int find(int i,int ql,int qr,int k)
{
if(tree[i].l==tree[i].r)
{
if(tree[i].sum&(1ll<<k)) return 0;
else return tree[i].l;
}
push_down(i);
if(!((tree[i].v2>>k)&1)&&!((tree[i].v1>>k)&1)) return 0;
if(ql<=tree[i].l&&tree[i].r<=qr)
{
if(tree[ls].sum&(1ll<<k)) return find(rs,ql,qr,k);
else return find(ls,ql,qr,k);
}
int p=0;
if(ql<=tree[ls].r) p=find(ls,ql,qr,k);
if(p) return p;
if(qr>=tree[rs].l) p=find(rs,ql,qr,k);
return p;
}
}T;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>a[i];
T.build(1,1,n);
while(q--)
{
int op;
cin>>op;
if(op==1)
{
int l,r,x;
cin>>l>>r>>x;
T.modify(1,l,r,x);
}
else if(op==2)
{
int s,x;
cin>>s>>x;
T.modify(1,s,x);
}
else if(op==3)
{
int l,r;
cin>>l>>r;
auto res=T.query(1,l,r);
int k=0;
for(int i=62;i>=0;i--)
if((!((res.v2>>i)&1))&&((res.v1>>i)&1))
{
k=i;
break;
}
int p=T.find(1,l,r,k);
long long ans=~0ll;
if(p==0) ans=res.sum;
else
{
if(l<=p-1) ans&=T.query(1,l,p-1).sum;
if(p+1<=r) ans&=T.query(1,p+1,r).sum;
}
if(ans<0) ans=-ans;
cout<<ans<<"\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5612kb
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: -100
Wrong Answer
time: 1ms
memory: 5608kb
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:
result:
wrong answer 1st lines differ - expected: '1568091718842717482', found: ''