QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21816#2831. Game TheoryWhybullYMe#WA 59ms3792kbC++141.6kb2022-03-08 16:11:082022-05-08 04:06: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:06:35]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:3792kb
  • [2022-03-08 16:11:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ri int
typedef long long ll;
const int maxn=2e5+10;
template<class T>inline bool ckmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T>inline bool ckmax(T &x,const T &y){return x<y?x=y,1:0;}
template<class T>inline void clear(T *arr,int siz,int val=0){memset(arr,val,sizeof(T)*(siz+1));}
struct segment_tree{
	int l,r,cnt;
	ll sum;
	bool tag;
}t[maxn<<2];
#define ls(p) (p<<1)
#define rs(p) (p<<1|1)
inline void push_up(int p){
	t[p].cnt=t[ls(p)].cnt+t[rs(p)].cnt;
	t[p].sum=t[ls(p)].sum+t[rs(p)].sum;
}
char s[maxn];
void build(int p,int l,int r){
	t[p].l=l,t[p].r=r;
	if(l==r){
		if(s[l])t[p].cnt=1,t[p].sum=l;
		else t[p].cnt=t[p].sum=0;
		return;
	}
	ri mid=l+r>>1;
	build(ls(p),l,mid);
	build(rs(p),mid+1,r);
	push_up(p);
}
inline void add_tag(int p){
	t[p].cnt=t[p].r-t[p].l+1-t[p].cnt;
	t[p].sum=1ll*(t[p].l+t[p].r)*(t[p].r-t[p].l+1)/2-t[p].sum;
	t[p].tag^=1;
}
inline void push_down(int p){
	if(!t[p].tag)return;
	add_tag(ls(p));
	add_tag(rs(p));
	t[p].tag=0;
}
#define no_intersection (t[p].l>r||l>t[p].r)
#define is_subset (l<=t[p].l&&t[p].r<=r)
void modify(int p,int l,int r){
	if(no_intersection)return;
	if(is_subset){
		add_tag(p);
		return;
	}
	push_down(p);
	modify(ls(p),l,r);
	modify(rs(p),l,r);
	push_up(p);
}
int n,q;
int main(){
	while(~scanf("%d%d",&n,&q)){
		scanf("%s",s);
		for(ri i=0;i<n;++i)s[i]^=48;
		build(1,0,n-1);
		while(q--){
			ri l,r;
			scanf("%d%d",&l,&r);
			modify(1,l-1,r-1);
			printf("%lld\n",((t[1].sum+t[1].cnt)*2-1ll*t[1].cnt*t[1].cnt)%998244353);
		}
		memset(s,0,n);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

1 1
0
1 1

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 59ms
memory: 3780kb

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
3
1
3
0
1
0
1
2
0
0
2
0
1
2
0
1
3
1
0
1
0
1
0
0
1
3
2
1
0
1
3
3
2
1
0
1
0
0
1
0
1
0
2
0
3
0
1
2
1
1
0
2
0
2
3
1
0
0
1
2
0
0
1
0
1
0
1
1
0
1
0
2
0
2
0
0
1
2
3
1
0
1
0
1
0
0
1
0
1
0
1
2
0
1
2
1
0
0
1
1
0
1
0
1
2
0
2
1
0
0
3
1
2
0
1
3
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
3
1
0
3
0
1
0
1
...

result:

wrong answer 22nd lines differ - expected: '2', found: '0'