QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#40065#2831. Game Theoryhit47TL 134ms7816kbC++1.8kb2022-07-16 00:42:512022-07-16 00:42:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-16 00:42:52]
  • 评测
  • 测评结果:TL
  • 用时:134ms
  • 内存:7816kb
  • [2022-07-16 00:42:51]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long 
const ll mod=998244353,N=2e5+10;
using namespace std;
int tree[N*4],lan[N*4],n;
char s[N];
void build(int root,int l,int r)
{
	lan[root]=0;
	if(l==r){
		tree[root]=(int)(s[l]-'0');
		return;
	}
	int mid=l+r>>1;
	build(root<<1,l,mid);
	build(root<<1|1,mid+1,r);
	tree[root]=tree[root<<1]+tree[root<<1|1];
}
void update(int root,int l,int r,int left,int right)
{
	if(lan[root])
	{
		lan[root]=0;
		int mid=l+r>>1;
		if(l!=r)lan[root<<1]=1,lan[root<<1|1]=1,tree[root<<1]=mid+1-l-tree[root<<1],tree[root<<1|1]=r-mid-tree[root<<1|1];
	}
	if(l>=left && r<=right)
	{
		tree[root]=r+1-l-tree[root];lan[root]=1;
		return;
	}
	if(l>right || r<left)return;
	int mid=l+r>>1;
	update(root<<1,l,mid,left,right);
	update(root<<1|1,mid+1,r,left,right);
	tree[root]=tree[root<<1]+tree[root<<1 | 1];
}
int query(int root,int l,int r,int left,int right)
{
	if(lan[root])
	{
		lan[root]=0;
		int mid=l+r>>1;
		if(l!=r)lan[root<<1]=1,lan[root<<1|1]=1,tree[root<<1]=mid+1-l-tree[root<<1],tree[root<<1|1]=r-mid-tree[root<<1|1];
	}
	if(l>=left && r<=right)return tree[root];
	if(l>right || r<left)return 0;
	int mid=l+r>>1;
	return query(root<<1,l,mid,left,right)+query(root<<1|1,mid+1,r,left,right);
}
long long erfen(int l,int r)
{
	if(l==r)return 0;
	int mid=l+r>>1;
	return query(1,1,n,mid+1,r)*(mid+1-l-query(1,1,n,l,mid))*2+erfen(l,mid)+erfen(mid+1,r);
}
int main()
{
	int q,i,j;
	long long ans,k,t;
	while(scanf("%d%d",&n,&q)!=EOF)
	{
		scanf("%s",s+1);
		build(1,1,n);
		k=0;
		for(i=n;i>=1;--i)
		if(s[i]=='1')ans++,k++;
		else ans+=k;
		for(i=1;i<=q;++i)
		{
			int l,r;
			scanf("%d%d",&l,&r);
			update(1,1,n,l,r);
			ans=erfen(1,n)+query(1,1,n,1,n);
			printf("%lld\n",ans%mod);
		}
	}
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 5772kb

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

input:

1 1
0
1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 58ms
memory: 5740kb

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

ok 200000 lines

Test #4:

score: 0
Accepted
time: 134ms
memory: 7816kb

input:

11 20
00010111000
1 6
1 11
5 6
8 11
1 4
3 8
4 11
1 7
5 9
1 4
6 10
5 6
1 7
5 10
1 10
9 11
6 8
1 4
8 11
1 4
10 20
0101000010
3 4
2 2
4 8
4 6
6 7
3 7
3 3
1 5
1 5
6 8
2 2
2 4
2 6
5 7
1 3
2 5
6 8
7 9
5 8
3 10
4 20
1011
2 4
1 4
1 3
2 3
1 1
2 2
1 2
2 4
1 2
3 4
3 4
3 4
1 4
2 2
1 4
1 3
1 1
1 3
1 3
2 2
4 20
1...

output:

16
55
53
25
13
15
43
52
41
33
34
40
43
45
35
28
25
33
45
37
19
20
35
38
36
41
36
29
36
29
22
31
20
23
28
20
21
10
14
30
2
10
5
7
10
9
7
2
0
10
0
10
2
1
9
6
7
4
7
8
4
9
1
6
8
3
5
7
3
7
6
8
6
9
6
7
2
0
5
3
66
105
83
68
92
137
92
76
85
92
127
120
119
104
124
65
70
88
61
53
40
43
25
21
32
59
67
32
29
50...

result:

ok 200000 lines

Test #5:

score: -100
Time Limit Exceeded

input:

11 200
11100010010
2 3
3 7
1 7
3 10
1 3
7 11
2 8
4 8
9 10
9 11
2 7
1 4
9 11
6 7
4 4
8 10
2 6
2 3
1 2
5 7
2 7
1 3
3 4
2 10
9 10
6 11
3 11
3 9
9 10
2 6
5 10
1 8
4 9
6 7
8 11
3 9
7 10
1 9
4 5
5 8
5 7
2 7
6 8
10 10
5 10
7 11
1 11
6 10
2 11
1 4
4 8
6 11
7 10
8 10
4 5
7 10
7 8
4 4
1 6
7 11
3 5
4 9
3 9
8 1...

output:

27
22
29
25
30
39
34
17
15
12
18
22
33
35
40
45
54
36
34
37
39
52
54
37
39
33
40
51
37
46
52
24
26
24
16
7
35
30
32
40
39
37
28
15
41
28
39
4
26
54
49
31
39
26
28
44
46
41
35
26
17
31
24
28
30
22
38
13
18
60
38
36
49
41
41
43
27
28
54
41
14
16
7
8
20
22
45
26
27
20
21
12
27
31
28
21
39
37
39
30
31
2...

result: