QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196349#2831. Game TheoryCSU2023#WA 41ms13532kbC++142.8kb2023-10-01 16:09:352023-10-01 16:09:35

Judging History

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

  • [2023-10-01 16:09:35]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:13532kb
  • [2023-10-01 16:09:35]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
using std::cin;
using std::cout;
using std::ios;
using std::max;
using std::min;
using std::swap;
const int N = 4e5 + 3;
const LL mod = 998244353;
char s[N];
int n,q;
struct Tree{
	int t;
	struct node{
		int lc,rc;
		int tag;
		LL sum[2];
		LL psum[2];
	}a[N << 1];
	inline void pushup(int u){
		for(int i = 0;i < 2;++i){
			a[u].sum[i] = a[a[u].lc].sum[i] + a[a[u].rc].sum[i];
			a[u].psum[i] = a[a[u].lc].psum[i] + a[a[u].rc].psum[i];	
		}
	}
	inline void pushdown(int u){
		if(!a[u].tag) return ;
		a[a[u].lc].tag ^= 1;
		a[a[u].rc].tag ^= 1;
		swap(a[a[u].lc].sum[0],a[a[u].lc].sum[1]);	
		swap(a[a[u].lc].psum[0],a[a[u].lc].psum[1]);
		swap(a[a[u].rc].sum[0],a[a[u].rc].sum[1]);
		swap(a[a[u].rc].psum[0],a[a[u].rc].psum[1]);
		a[u].tag = 0;
	}
	inline void build(int &u,int l,int r){
		if(!u) u = ++t;
		a[u].lc = a[u].rc = a[u].tag = a[u].sum[0] = a[u].sum[1] = a[u].psum[1] = a[u].psum[0] = 0;
		if(l == r){
			a[u].sum[s[l] - '0'] = 1;
			a[u].psum[s[l] - '0'] = l;
			return ;
		}
		int mid = (l + r) >> 1;
		build(a[u].lc,l,mid);
		build(a[u].rc,mid + 1,r);
		pushup(u);
	}
	inline void updata(int u,int l,int r,int ll,int rr){
		if(l == ll && r == rr){
			swap(a[u].sum[0],a[u].sum[1]);
			swap(a[u].psum[0],a[u].psum[1]);
			a[u].tag ^= 1;
			return ;
		}
		pushdown(u);
		int mid = (l + r) >> 1;
		if(rr <= mid) updata(a[u].lc,l,mid,ll,rr);
		else if(ll > mid) updata(a[u].rc,mid + 1,r,ll,rr);
		else updata(a[u].lc,l,mid,ll,mid),updata(a[u].rc,mid + 1,r,mid + 1,rr);
		pushup(u);
	}
	inline LL query(int u,int l,int r,int ll,int rr,int w){
		if(ll > rr) return 0;
		if(l == ll && r == rr) return a[u].psum[w];
		pushdown(u);
		int mid = (l + r) >> 1;
		if(rr <= mid) return query(a[u].lc,l,mid,ll,rr,w);
		else if(ll > mid) return query(a[u].rc,mid + 1,r,ll,rr,w);
		else return query(a[u].lc,l,mid,ll,mid,w) + query(a[u].rc,mid + 1,r,mid + 1,rr,w);	
	}
	inline LL get1(int u){
		return a[u].sum[1];
	}
	inline int getpos(int u,int l,int r,int x){
		if(l == r) return a[u].sum[0] ? 0 : 1;
		pushdown(u);
		int mid = (l + r) >> 1;
		if(x <= mid) return getpos(a[u].lc,l,mid,x);
		else return getpos(a[u].rc,mid + 1,r,x);
	}
}T;
int main(){
	while(scanf("%d%d",&n,&q) != EOF){
		int rt = 0;
		scanf("%s",s + 1);
		T.build(rt,1,n);
		while(q--){
			int l ,r;
			scanf("%d%d",&l,&r);
			T.updata(rt,1,n,l,r);
			int s1 = T.get1(rt);
			int p = T.getpos(rt,1,n,s1);
			if(!s1) printf("%lld\n",(T.query(rt,1,n,s1 + 1,n,1) * 2 - T.query(rt,1,n,1,s1 - 1,0) * 2 - s1) % mod);
			else printf("%lld\n",(T.query(rt,1,n,s1 + 1,n,1) * 2 + s1 - T.query(rt,1,n,1,s1 - 1,0) * 2) % mod);
		}
	}
    return 0;
}





详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3620kb

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: 1ms
memory: 5752kb

input:

1 1
0
1 1

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 41ms
memory: 13532kb

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:

0
5
1
5
0
1
0
1
2
0
0
2
0
1
2
0
1
5
1
0
1
2
1
0
0
1
5
2
1
0
1
5
5
2
1
0
1
0
0
1
0
1
0
2
2
1
0
1
2
1
1
0
2
0
2
5
1
0
0
1
2
0
0
1
0
1
0
1
1
0
1
2
2
0
0
2
0
1
0
1
1
0
1
0
1
0
0
1
0
1
0
1
2
0
5
0
1
0
0
1
1
0
1
0
1
2
0
2
1
0
0
5
1
2
0
1
5
2
1
0
0
1
2
0
2
0
0
1
0
1
1
0
1
0
1
0
1
0
1
2
1
0
5
1
0
5
0
1
0
1
...

result:

wrong answer 2nd lines differ - expected: '3', found: '5'