QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#103845 | #2831. Game Theory | yl_9# | RE | 3ms | 7488kb | C++14 | 2.0kb | 2023-05-07 18:18:16 | 2023-05-07 18:18:20 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=2e5+9,mod=998244353;
int n,q;
int sum[N<<2][2],lazy[N<<2],o[N<<2];
char s[N];
int add(int x,int y)
{
return (x+y)%mod;
}
void pushup(int x)
{
o[x]=add(o[x<<1],o[x<<1|1]);
sum[x][0]=add(sum[x<<1][0],sum[x<<1|1][0]);
sum[x][1]=add(sum[x<<1][1],sum[x<<1|1][1]);
}
void build(int x,int l,int r)
{
lazy[x]=0;
if(l==r)
{
o[x]=(s[l]=='1');
sum[x][(s[l]-'0')]=l;
sum[x][(s[l]-'0')^1]=0;
return;
}
int mid=(l+r)>>1;
build(x<<1,l,mid);
build(x<<1|1,mid+1,r);
pushup(x);
}
void pushdown(int x,int l,int r)
{
if(!lazy[x]) return;
int mid=(l+r)>>1;
o[x<<1]=mid-l+1-o[x<<1];
o[x<<1|1]=r-mid-o[x<<1|1];
swap(sum[x<<1][0],sum[x<<1][1]);
swap(sum[x<<1|1][0],sum[x<<1|1][1]);
lazy[x<<1]^=1;
lazy[x<<1|1]^=1;
lazy[x]=0;
}
void update(int x,int l,int r,int L,int R)
{
if(L<=l&&r<=R)
{
swap(sum[x][0],sum[x][1]);
o[x]=(r-l+1)-o[x];
lazy[x]^=1;
return;
}
pushdown(x,l,r);
int mid=(l+r)>>1;
if(mid>=L) update(x<<1,l,mid,L,R);
if(mid+1<=R) update(x<<1|1,mid+1,r,L,R);
pushup(x);
}
int findo(int x,int l,int r,int k)
{
if(l==k&&r==k) return o[x];
pushdown(x,l,r);
int mid=(l+r)>>1;
if(k<=mid) return findo(x<<1,l,mid,k);
else return findo(x<<1|1,mid+1,r,k);
}
int findsum(int x,int l,int r,int L,int R,int op)
{
if(L<=l&&r<=R) return sum[x][op];
pushdown(x,l,r);
int mid=(l+r)>>1;
LL res=0;
if(mid>=L) res=add(res,findsum(x<<1,l,mid,L,R,op));
if(mid+1<=R) res=add(res,findsum(x<<1|1,mid+1,r,L,R,op));
return res;
}
void solve()
{
cin>>s+1;
build(1,1,n);
while(q--)
{
int l,r;
cin>>l>>r;
update(1,1,n,l,r);
int k=o[1];
int flag=findo(1,1,n,k);
LL ans=findsum(1,1,n,k,n,1)*2ll-findsum(1,1,n,1,k,0)*2ll;
if(flag) ans-=findsum(1,1,n,k,k,1);
else ans+=findsum(1,1,n,k,k,0);
cout<<add(ans%mod,mod)<<"\n";
}
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
while(cin>>n>>q) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7488kb
input:
3 2 010 1 2 2 3 5 1 00000 1 5
output:
1 3 5
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 3ms
memory: 7412kb
input:
1 1 0 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Runtime Error
input:
2 2 01 2 2 2 2 2 2 01 1 2 1 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 2 00 1 2 1 2 2 2 11 1 2 1 2 2 2 01 2 2 1 1 2 2 10 2 2 1 2 2 2 01 1 2 1 2 1 2 0 1 1 1 1 2 2 01 1 2 2 2 1 2 0 1 1 1 1 1 2 1 1 1 1 1 2 2 10 1 2 1 1 1 2 0 1 1 1 1 2 2 01 1 2 1 2 2 2 10 1 2 1 1 1 2 0 1 1 1 1 1 2 0 1 1 1 1 1 2 1 1 1 1 1 2 2 10 1 ...