QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737173 | #2831. Game Theory | lingying | WA | 1ms | 9916kb | C++14 | 1.2kb | 2024-11-12 14:54:39 | 2024-11-12 14:54:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int mod=998244353;
int n,m;
int len[4*N],cnt[4*N],lazy[4*N];
ll dat[4*N],sum[4*N];
char s[N];
#define lson p*2
#define rson p*2+1
void pushup(int p)
{
cnt[p]=cnt[lson]+cnt[rson];
dat[p]=dat[lson]+dat[rson];
}
void upd(int p)
{
lazy[p]^=1;
cnt[p]=len[p]-cnt[p];
dat[p]=sum[p]-dat[p];
}
void pushdown(int p)
{
if(lazy[p])
{
upd(lson);
upd(rson);
lazy[p]=0;
}
}
void build(int p,int l,int r)
{
len[p]=r-l+1,sum[p]=1ll*(l+r)*(r-l+1)/2;
if(l==r)return cnt[p]=s[l]-'0',dat[p]=(s[l]-'0')*l,void();
int mid=l+r>>1;
build(lson,l,mid),build(rson,mid+1,r);
pushup(p);
}
void update(int p,int lt,int rt,int l,int r)
{
if(l<=lt&&rt<=r)return upd(p),void();
pushdown(p);
int mid=lt+rt>>1;
if(l<=mid)update(lson,lt,mid,l,r);
if(r>mid)update(rson,mid+1,rt,l,r);
pushup(p);
}
#undef lson
#undef rson
int main()
{
scanf("%d%d%s",&n,&m,s+1);
build(1,1,n);
while(m--)
{
int l,r;
scanf("%d%d",&l,&r);
update(1,1,n,l,r);
int t1=cnt[1];
int t2=1ll*cnt[1]*(cnt[1]+1)%mod;
int t3=2ll*dat[1]%mod;
int ans=(1ll*t1+t3-t2+mod)%mod;
cout<<ans<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 9916kb
input:
3 2 010 1 2 2 3 5 1 00000 1 5
output:
1 3
result:
wrong answer 3rd lines differ - expected: '5', found: ''