QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#103851#2831. Game Theoryyl_9#RE 3ms7420kbC++142.0kb2023-05-07 18:24:162023-05-07 18:24:20

Judging History

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

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

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<<3][2],lazy[N<<3],o[N<<3];
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;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 7340kb

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: 7420kb

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 ...

output:


result: