QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21827#2831. Game TheoryQyc_AK_NOI2022#RE 0ms0kbC++142.2kb2022-03-08 16:27:202022-05-08 04:07:35

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 04:07:35]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-03-08 16:27:20]
  • 提交

answer

#include <cstdio>
using namespace std;
typedef long long ll;
inline int rd(){
	int x=0;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c==EOF)return -1;
		c=getchar();
	}
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x;
}
const int mod=998244353;
struct node{
	bool tag;
	int hv0,hv1,sum0,sum1;
}t[800010];
int n,q,s[200010];
inline int rdc(){
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	return c^48;
}
inline int fx(int x){return x>=mod?x-mod:x;}
inline void refresh(int p){
	t[p].sum0=fx(t[p<<1].sum0+t[p<<1|1].sum0);
	t[p].sum1=fx(t[p<<1].sum1+t[p<<1|1].sum1);
	t[p].hv0=t[p<<1].hv0+t[p<<1|1].hv0;
	t[p].hv1=t[p<<1].hv1+t[p<<1|1].hv1;
}
inline void swp(int &x,int &y){x^=y^=x^=y;}
void build(int l,int r,int p){
	if(l==r){
		t[p]=(node){0,!s[l],s[l],(!s[l])*l,s[l]*l};
		return;
	}
	int mid=l+r>>1;
	t[p].tag=0;
	build(l,mid,p<<1),build(mid+1,r,p<<1|1);
	refresh(p);
}
inline void adt(int p){
	t[p].tag^=1;
	swp(t[p].hv0,t[p].hv1);
	swp(t[p].sum0,t[p].sum1);
}
inline void pushdown(int p){
	if(t[p].tag){
		t[p].tag=0;
		adt(p<<1),adt(p<<1|1);
	}
}
void filp(int l,int r,int p,int b,int e){
	if(b<=l && e>=r)return adt(p);
	pushdown(p);
	int mid=l+r>>1;
	if(b<=mid)filp(l,mid,p<<1,b,e);
	if(e>mid)filp(mid+1,r,p<<1|1,b,e);
	refresh(p);
}
int qus0(int l,int r,int p,int e){
	if(e>=r)return fx(fx(((ll)(e+1)*t[p].hv0+mod-t[p].sum0)%mod<<1)+mod-t[p].hv0);
	pushdown(p);
	int mid=l+r>>1,ans=qus0(l,mid,p<<1,e);
	if(e>mid)ans=fx(ans+qus0(mid+1,r,p<<1|1,e));
	return ans;
}
int qus1(int l,int r,int p,int b){
	if(b<=l)return fx(fx(t[p].sum1+mod-(ll)(b-1)*t[p].hv1%mod<<1)+mod-t[p].hv1);
	pushdown(p);
	int mid=l+r>>1,ans=qus1(mid+1,r,p<<1|1,b);
	if(b<=mid)ans=fx(ans+qus1(l,mid,p<<1,b));
	return ans;
}
inline int qus0(int p){
	if(!p)return 0;
	return qus0(1,n,1,t[1].hv1-1);
}
inline int qus1(int p){
	return qus1(1,n,1,t[1].hv1);
}
int main(){
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	while((n=rd())!=-1){
		q=rd();
		for(int i=1;i<=n;++i)s[i]=rdc();
		build(1,n,1);
		for(int i=1,l,r;i<=q;++i){
			l=rd(),r=rd(),filp(1,n,1,l,r);
			if(!t[1].hv1){puts("0");continue;}
			printf("%d\n",fx(t[1].hv1-1+qus0(t[1].hv1-1)+qus1(t[1].hv1)));
		}
	}
	return 0;
}

详细

Test #1:

score: 0
Dangerous Syscalls

input:

3 2
010
1 2
2 3
5 1
00000
1 5

output:


result: