QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#563844 | #9263. Rebellious Sequences | PhantomThreshold# | WA | 1ms | 7996kb | C++20 | 2.3kb | 2024-09-14 16:18:08 | 2024-09-14 16:18:08 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 310000;
int n,m;
int a[maxn],pa[maxn];
struct segment
{
int mn[maxn<<2],flag[maxn<<2];
void build(const int x,const int l,const int r)
{
flag[x]=0;
if(l==r)
{
mn[x]=pa[l];
return;
}
int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
build(lc,l,mid); build(rc,mid+1,r);
mn[x]=min(mn[lc],mn[rc]);
}
void pushdown(const int x)
{
if(!flag[x]) return;
int fl=flag[x]; flag[x]=0;
int lc=x<<1,rc=lc|1;
mn[lc]+=fl, flag[lc]+=fl;
mn[rc]+=fl, flag[rc]+=fl;
}
int lx,rx,c;
void upd(const int x,const int l,const int r)
{
if(rx<l||r<lx) return;
if(lx<=l&&r<=rx)
{
flag[x]+=c;
mn[x]+=c;
return;
}
pushdown(x);
int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
upd(lc,l,mid); upd(rc,mid+1,r);
mn[x]=min(mn[lc],mn[rc]);
}
int query(const int x,const int l,const int r)
{
if(rx<l||r<lx) return 1;
if(lx<=l&&r<=rx) return mn[x];
pushdown(x);
int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
return min( query(lc,l,mid), query(rc,mid+1,r) );
}
}seg;
set<int>S;
void check(int i)
{
if(i<n && a[i]==-1 && a[i+1]==1) S.insert(i);
else S.erase(i);
}
int calc()
{
if(S.size()>1u)
{
auto it=S.begin();
seg.lx=(*it)+1;
it=S.end(); it--;
seg.rx=(*it)-1;
if(seg.query(1,1,n)==0) return 1;
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
string ss; cin>>ss;
for(int i=1;i<=n;i++)
{
a[i]= ss[i-1]=='('?1:-1;
pa[i]=pa[i-1]+a[i];
}
seg.build(1,1,n);
while(m--)
{
int x,y; cin>>x>>y;
if(x>y) swap(x,y);
if(x!=y && a[x]!=a[y])
{
seg.lx=x,seg.rx=y-1,seg.c=a[y]-a[x];
seg.upd(1,1,n);
swap(a[x],a[y]);
check(x-1);
check(x);
check(y-1);
check(y);
}
if(calc()) cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5908kb
input:
8 4 (()()()) 3 4 5 6 2 7 6 7
output:
No No Yes No
result:
ok 4 token(s): yes count is 1, no count is 3
Test #2:
score: 0
Accepted
time: 1ms
memory: 7752kb
input:
6 6 ((())) 2 4 2 4 2 5 4 5 4 5 2 3
output:
No No No No No No
result:
ok 6 token(s): yes count is 0, no count is 6
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 7996kb
input:
10 10 ((())(())) 7 9 2 4 5 6 8 9 2 8 5 9 2 5 2 3 3 9 3 8
output:
No No No No No No No No No No
result:
wrong answer expected YES, found NO [2nd token]