QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#103152 | #2831. Game Theory | QZJ123456 | WA | 2ms | 5596kb | C++14 | 1.9kb | 2023-05-04 16:50:15 | 2023-05-04 16:50:17 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int n,q;
const ll mod=998244353;
struct node{
int l,r,lazy,cnt;
ll sum;
}Tree[800005];
char s[200005];
int a[200005];
void pushup(int p){
Tree[p].sum=(Tree[p*2].sum+Tree[p*2+1].sum)%mod;
Tree[p].cnt=Tree[p*2].cnt+Tree[p*2+1].cnt;
}
void ztree(int p,int l,int r){
Tree[p].l=l,Tree[p].r=r;
Tree[p].lazy=0;
if(l==r){
Tree[p].cnt=a[l];
Tree[p].sum=1ll*a[l]*l;
return;
}
int mid=l+r>>1;
ztree(p*2,l,mid);
ztree(p*2+1,mid+1,r);
pushup(p);
}
ll Gs(int l,int r){
ll a=1ll*(l+r)*(r-l+1)/2;
return a%mod;
}
void pushdown(int p){
if(!Tree[p].lazy)return;
Tree[p*2].lazy^=1;
Tree[p*2].cnt=(Tree[p*2].r-Tree[p*2].l+1)-Tree[p*2].cnt;
Tree[p*2].sum=(Gs(Tree[p*2].l,Tree[p*2].r)-Tree[p*2].sum+mod)%mod;
Tree[p*2+1].lazy^=1;
Tree[p*2+1].cnt=(Tree[p*2+1].r-Tree[p*2+1].l+1)-Tree[p*2+1].cnt;
Tree[p*2+1].sum=(Gs(Tree[p*2+1].l,Tree[p*2+1].r)-Tree[p*2+1].sum+mod)%mod;
Tree[p].lazy=0;
}
void update(int p,int l,int r){
if(l<=Tree[p].l&&Tree[p].r<=r){
Tree[p].lazy^=1;
Tree[p].cnt=(Tree[p].r-Tree[p].l+1)-Tree[p].cnt;
Tree[p].sum=(Gs(Tree[p].l,Tree[p].r)-Tree[p].sum+mod)%mod;
return;
}
pushdown(p);
int mid=Tree[p].l+Tree[p].r>>1;
if(l<=mid)update(p*2,l,r);
if(r>mid)update(p*2+1,l,r);
pushup(p);
}
ll Getsum(int p,int l,int r){
if(l<=Tree[p].l&&Tree[p].r<=r){
return Tree[p].sum;
}
pushdown(p);
int mid=Tree[p].l+Tree[p].r>>1;
ll c=0;
if(l<=mid)c=Getsum(p*2,l,r);
if(r>mid)c=(c+Getsum(p*2+1,l,r))%mod;
return c;
}
int main(){
scanf("%d%d",&n,&q);
scanf("%s",s+1);
for(int i=1;i<=n;i++)a[i]=s[i]-'0';
ztree(1,1,n);
while(q--){
int l,r;
scanf("%d%d",&l,&r);
update(1,l,r);
int p=Tree[1].cnt;
ll ans=0;
if(p!=n)ans+=Getsum(1,p+1,n);
ans-=(Gs(1,p)-Getsum(1,1,p)+mod)%mod;
printf("%lld\n",(ans*2ll+p+mod)%mod);
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5596kb
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: ''