QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#706426#9464. 基础 01? 练习题Aaronwrq#25 2459ms331040kbC++142.3kb2024-11-03 11:15:562024-11-03 11:15:57

Judging History

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

  • [2024-11-03 11:15:57]
  • 评测
  • 测评结果:25
  • 用时:2459ms
  • 内存:331040kb
  • [2024-11-03 11:15:56]
  • 提交

answer

#include <bits/stdc++.h>
#define MAXN 4010
using namespace std;

int n, m, q, ck[MAXN], po2[MAXN];
string S, T;
int hpo[MAXN][2], hp[2] = {131, 13131}, hm[2] = {998244353, 1000000007};
int s[MAXN][MAXN];
unordered_map<long long, bool> mp;
const int mod = 998244353, i2 = (mod + 1) >> 1;

void Addc(long long &nowh0, long long &nowh1, int c) {
	nowh0 = (nowh0 * hp[0] + c) % hm[0];
	nowh1 = (nowh1 * hp[1] + c) % hm[1];
	return;
}

void dfs(const int p) {
	if (p >= n) {
		long long nowh0 = 0, nowh1 = 0;
		for (int i = 0, j = -1; i < n; ++i) {
			while (j < i) ++j, Addc(nowh0, nowh1, S[j]);
			while (j < n - 1) {
				long long newh0 = nowh0, newh1 = nowh1;
				Addc(newh0, newh1, S[j + 1]);
				if (mp[(newh0 << 30) | newh1]) ++j, nowh0 = newh0, nowh1 = newh1;
				else break;
			}
			++s[i][i], --s[i][j + 1];
			nowh0 = (nowh0 + 1ll * (hm[0] - hpo[j - i][0]) * S[i]) % hm[0];
			nowh1 = (nowh1 + 1ll * (hm[1] - hpo[j - i][1]) * S[i]) % hm[1];
		}
		return;
	}
	if (S[p] != '?') dfs(p + 1);
	else {
		S[p] = '0', dfs(p + 1);
		S[p] = '1', dfs(p + 1);
		S[p] = '?';
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> q >> S;
	T = "0", m = n << 3;
	for (int i = 1; i < m; ++i) T += T[i >> 1] ^ (i & 1);
	hpo[0][0] = hpo[0][1] = 1;
	for (int i = 1; i < m; ++i) {
		hpo[i][0] = 1ll * hpo[i - 1][0] * hp[0] % hm[0];
		hpo[i][1] = 1ll * hpo[i - 1][1] * hp[1] % hm[1];
	}
	for (int i = 0; i < n; ++i) ck[i] = S[i] == '?';
	for (int i = 1; i < n; ++i) ck[i] += ck[i - 1];
	po2[0] = 1;
	for (int i = 1; i <= n; ++i) po2[i] = 1ll * po2[i - 1] * i2 % mod;
	for (int i = 0; i < m; ++i) {
		long long nowh0 = 0, nowh1 = 0;
		for (int j = i; j < m; ++j) {
			Addc(nowh0, nowh1, T[j]);
			mp[(nowh0 << 30) | nowh1] = 1;
		}
	}
	dfs(0);
	for (int i = 0; i < n; ++i) for (int j = 1; j < n; ++j) s[i][j] += s[i][j - 1];
	for (int i = 0; i < n; ++i) for (int j = 1; j < n; ++j) s[i][j] = (s[i][j] + s[i][j - 1]) % mod;
	for (int i = 1; i < n; ++i) for (int j = 0; j < n; ++j) s[i][j] = (s[i][j] + s[i - 1][j]) % mod;
	while (q--) {
		int l, r; cin >> l >> r;
		int ans = s[n - 1][r], cc = ck[r];
		if (l) ans = (ans + mod - s[l - 1][r]) % mod, cc -= ck[l - 1];
		cout << 1ll * ans * po2[ck[n - 1] - cc] % mod << "\n";
	}
	return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 3844kb

input:

15 15
0???0??01???1??
2 14
0 9
6 10
1 14
1 14
0 12
5 14
6 7
0 6
4 14
1 12
10 10
0 14
1 12
4 7

output:

25883
2344
112
56425
56425
12963
4531
6
666
5212
11875
2
60786
11875
37

result:

ok 15 numbers

Test #2:

score: 10
Accepted
time: 1ms
memory: 3952kb

input:

15 15
011?1?0101??110
0 11
2 10
0 13
2 12
3 5
2 12
3 5
12 13
1 14
1 5
8 13
9 12
2 10
0 11
7 8

output:

803
285
952
732
23
732
23
3
940
48
69
37
285
803
3

result:

ok 15 numbers

Test #3:

score: 10
Accepted
time: 1ms
memory: 5864kb

input:

15 15
100110?1010?01?
9 9
6 11
1 4
0 13
7 7
9 13
3 14
0 0
0 13
0 12
0 10
6 11
4 8
3 13
0 13

output:

1
77
10
265
1
25
384
1
265
251
109
77
30
175
265

result:

ok 15 numbers

Test #4:

score: 10
Accepted
time: 4ms
memory: 4060kb

input:

15 15
??????0?0??????
8 10
0 14
9 12
2 13
1 6
7 12
0 13
6 14
0 11
0 14
4 14
5 14
0 8
4 5
1 13

output:

23
439848
146
41764
540
540
202272
3703
41802
439848
18776
8386
3703
12
92312

result:

ok 15 numbers

Test #5:

score: 10
Accepted
time: 1ms
memory: 4144kb

input:

15 15
?1??0?0??010?1?
3 14
4 5
0 14
0 13
4 8
12 13
1 5
5 8
11 13
3 3
1 12
0 2
5 14
11 12
4 12

output:

3128
6
15531
6994
99
6
101
73
12
2
2842
23
1305
6
522

result:

ok 15 numbers

Test #6:

score: 10
Accepted
time: 1ms
memory: 3740kb

input:

15 15
10????1001?11?1
0 14
0 5
0 14
5 13
4 9
10 14
6 13
0 14
1 9
0 13
6 13
1 11
1 13
9 13
4 5

output:

4184
279
4184
276
78
46
109
4184
531
3878
109
1446
3516
46
12

result:

ok 15 numbers

Subtask #2:

score: 10
Accepted

Test #7:

score: 10
Accepted
time: 45ms
memory: 6308kb

input:

20 200000
???10?10???????1????
1 19
2 17
5 19
6 19
6 15
5 19
1 11
0 15
4 6
3 16
10 13
12 18
16 16
0 15
7 14
2 11
14 19
9 16
0 18
11 16
7 13
1 17
5 18
7 7
6 10
4 17
5 19
2 9
0 16
1 19
5 14
4 19
0 11
0 16
15 19
0 12
1 15
4 17
13 16
3 14
4 13
5 13
3 10
0 19
2 17
6 18
0 18
7 10
3 18
10 14
1 13
0 16
0 19...

output:

1336712
138392
234942
106457
4426
234942
5914
141418
12
28991
146
1346
2
141418
3235
2622
540
3235
1346550
540
1346
298458
108555
1
107
55692
234942
504
300854
1336712
9100
258457
13090
300854
206
28541
65634
55692
73
12242
4720
3994
479
2835916
138392
48773
1346550
73
133840
412
28291
300854
283591...

result:

ok 200000 numbers

Test #8:

score: 10
Accepted
time: 21ms
memory: 5964kb

input:

20 200000
?10???1101001101??11
2 17
8 16
0 15
1 17
11 13
1 6
2 13
5 19
2 4
1 8
1 6
0 2
4 8
2 5
0 13
1 14
11 15
16 18
14 15
4 19
0 17
9 19
8 13
0 3
0 7
8 19
4 19
17 17
12 15
2 8
0 19
4 19
1 19
13 17
0 10
0 19
19 19
4 11
0 19
0 19
0 16
1 16
6 6
1 14
12 14
7 13
1 2
2 16
2 5
3 18
0 16
6 16
4 8
12 17
8 9...

output:

2760
82
1396
2948
6
141
463
636
23
209
141
12
51
73
1115
593
15
23
3
1380
6288
198
21
40
427
226
1380
2
10
168
6960
1380
3284
56
702
6960
1
123
6960
6960
2984
1394
1
593
6
28
3
1300
73
2780
2984
116
51
75
3
136
636
2944
226
1380
1300
6288
6960
141
602
175
35
23
2932
38
1396
3
29
12
294
593
6656
184
...

result:

ok 200000 numbers

Test #9:

score: 10
Accepted
time: 23ms
memory: 4288kb

input:

20 200000
01101010101?001?011?
2 8
8 19
2 16
11 17
0 16
7 19
3 11
0 14
16 18
4 9
6 19
4 17
6 12
7 10
2 19
6 17
0 12
1 19
0 19
3 8
0 18
2 14
1 19
10 14
2 19
9 19
2 15
13 14
3 15
9 13
12 19
12 14
1 12
6 6
13 15
0 15
10 18
0 19
0 19
8 17
0 18
0 13
7 11
4 5
1 19
1 18
1 17
7 12
0 16
1 19
1 10
10 18
1 2
3...

output:

22
406
247
96
291
460
61
122
6
18
492
242
48
10
620
210
102
660
708
18
338
100
660
26
620
352
224
3
208
27
116
6
90
1
12
268
136
708
708
167
338
111
29
3
660
314
294
40
291
660
35
136
3
18
230
167
708
18
352
1
18
21
141
25
226
12
20
72
12
708
26
1
210
10
99
50
274
29
708
274
33
50
588
73
167
192
708...

result:

ok 200000 numbers

Test #10:

score: 10
Accepted
time: 176ms
memory: 4240kb

input:

20 200000
????????0?????0?????
0 19
1 19
4 17
9 12
3 12
0 18
1 12
6 7
1 9
8 11
4 19
1 5
0 19
19 19
5 15
1 9
0 5
2 18
12 17
3 7
2 2
0 18
8 18
10 15
8 13
15 16
9 14
2 19
9 17
12 16
3 6
0 9
2 9
1 15
4 18
9 18
5 8
2 8
4 13
2 16
12 17
0 16
5 16
9 19
1 19
3 11
13 18
2 16
1 15
6 19
0 10
6 12
1 4
14 17
2 19...

output:

20336544
9597862
210735
146
17346
9597284
87146
12
7568
73
985734
412
20336544
2
19633
7568
1080
2114106
540
412
2
9597284
19606
540
540
12
540
4513692
7568
206
146
17346
3235
456646
457188
17346
73
1346
17346
456984
540
2113112
43751
39128
9597862
7568
540
456984
456646
210668
39128
1346
146
73
451...

result:

ok 200000 numbers

Test #11:

score: 10
Accepted
time: 28ms
memory: 4268kb

input:

20 200000
??10?1011?01????????
11 13
0 1
0 19
0 16
6 10
7 19
1 4
2 16
7 19
8 14
3 14
15 17
5 18
14 19
5 11
1 19
10 18
4 18
14 17
1 19
2 18
0 19
11 18
16 19
0 12
1 4
10 15
11 14
13 15
3 11
1 12
7 10
7 13
10 13
7 18
12 15
15 18
10 19
9 14
3 15
6 18
13 16
1 19
7 11
4 18
2 12
6 14
2 17
2 18
7 13
4 6
7 1...

output:

23
12
388332
41750
26
25671
40
8695
25671
378
1640
46
14667
1080
47
182132
3869
32150
146
182132
39318
388332
3235
146
1986
40
279
73
46
140
900
18
187
38
11717
146
146
8845
292
3576
13131
146
182132
27
32150
389
534
18527
39318
187
12
11717
86572
8695
900
140
12
2718
3101
35478
16608
388332
898
12
...

result:

ok 200000 numbers

Test #12:

score: 10
Accepted
time: 25ms
memory: 4296kb

input:

20 200000
?1??111??0?1??1?0100
17 19
12 15
9 10
0 18
15 19
3 11
2 19
0 2
4 13
4 13
1 15
0 19
0 19
5 8
5 9
4 16
0 19
5 8
2 9
17 17
10 15
3 13
2 16
5 17
0 18
11 19
0 17
3 18
12 16
0 19
13 17
6 18
5 9
0 16
0 2
2 9
4 18
2 17
0 19
4 18
0 3
5 12
0 19
0 8
7 16
4 7
0 17
14 18
0 13
0 17
5 18
4 10
1 12
0 18
1...

output:

6
73
6
37608
29
402
18272
23
1023
1023
13068
40576
40576
35
49
2995
40576
35
320
1
278
2206
13452
3263
37608
284
34104
7978
107
40576
57
3460
49
30936
23
320
3829
15036
40576
3829
73
405
40576
780
2365
15
34104
30
11672
34104
3701
144
2356
37608
2
380
106
2531
37608
2365
40576
15036
5
2
28248
13452
...

result:

ok 200000 numbers

Subtask #3:

score: 0
Runtime Error

Test #13:

score: 0
Runtime Error

input:

50000 200000
011001101001011?10011001011010010110011010011001011?011010010110?0011001011001101?011?010?10100101100110100110010110011?1001011010011001011?10010?1?0?10100101101?01100101100110100110010110?001011001101001100101100?10100101101?0110?10110011010011001011010010110011010010110100110?10110100...

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #19:

score: 0
Runtime Error

input:

50000 1
0101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010011001011001101001011010011001011010010110011010010110100110010110011010011001011010...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #25:

score: 0
Runtime Error

input:

50000 1
01011010011000110100110010110010?1001?0001011001101?001011001101?0101101?011011001101001010?10100101101001100101?01100101010?101001100110?1011010011001011010??110011?1?011001?1100110?101101001100101100100110010110011100110100101001?1?0?00?100101101001011001101001011100?1010010110101101001011...

output:


result:


Subtask #6:

score: 5
Accepted

Test #31:

score: 5
Accepted
time: 2411ms
memory: 330920kb

input:

500 1000
011000100010010010010010110010101100101100101011010010011001101001011010011000010011010001011010000001100101100110100101101001001011010010110010110100101100111001100111010011010010110100110010110100101100110101000101100110100110010110100101100110100101101?01101101100101011001010010100110010...

output:

399
1770
1496
922
2273
23256
14888
21468
5050
11956
7336
16724
1640
23288
23076
5699
23296
556
10300
23036
2274
14904
344
958
8912
1922
372
16048
14908
2830
20496
748
17988
22832
21300
22324
17996
23792
3
17104
19492
474
8664
14960
19820
339
1402
12048
24060
20344
19324
20304
5254
3962
20340
1532
52...

result:

ok 1000 numbers

Test #32:

score: 5
Accepted
time: 2356ms
memory: 331040kb

input:

500 1000
0010100100010011011101100101000010010110100101101001010010110101001?1001?0100100010010100010110110010111101110110001010010001011001010001010001001100101010011010110100110101111001001010101101000101100101100111011110110100100011010?101110010101111000101010000001110011010011000101100100101100...

output:

137
2544
479
2586
2756
19644
43352
2768
2692
12260
7068
92416
810
28
17768
91888
15836
15220
2618
327
3972
139
1504
7832
1069
12668
2576
45752
8904
2500
2582
94864
10356
95856
3446
15260
492
17572
15
43144
116
2898
81456
1738
3482
1130
4416
216
473
16884
2130
17812
39408
46312
3
2184
2774
224
7792
6...

result:

ok 1000 numbers

Test #33:

score: 5
Accepted
time: 2419ms
memory: 330848kb

input:

500 1000
101001001?11011010010111100110010110101010010001111?10101010001101011011001110100101110011010011101011101110110100101011000001000110110000101000010010011?0100100100010001010001010011010011010001?011010011001110110101101011110100011100100101110011011010110101101010110100001101001110000101101...

output:

11024
63280
293632
2683
21432
712
3282
26296
3014
51856
3280
319520
156
19816
150912
1655
4506
675776
1212
2286
17620
1130
1066
28424
2306
9816
8080
2014
128320
11132
658880
740
324
2986
316832
678848
2560
4204
65440
2118
1138
5146
26664
64880
188
7392
1
145808
20808
568
9720
8996
6648
70352
35
1175...

result:

ok 1000 numbers

Test #34:

score: 5
Accepted
time: 2405ms
memory: 330928kb

input:

500 1000
11010011001101101001011010110010100110110110?01001110101001010100111?010110011001001001101001110100101001100101101001001001101101001111100110100110010110011101100000100110111010001010011001101001011?1110011011101010010111001101101101101001010010001001011011001?010011001011110010?1100101?011...

output:

17104
869248
19664
56
198080
5168
12128
165472
65488
10
2716
913
385472
885248
50608
585
1760
14
356416
27440
185888
72336
1311
1794
438080
417472
1995
224
56432
270400
978
619
170624
402048
371520
416704
409728
85072
333632
1749
67568
26992
314688
1073
417216
406464
317248
897920
826368
52688
89459...

result:

ok 1000 numbers

Test #35:

score: 5
Accepted
time: 2459ms
memory: 330864kb

input:

500 1000
01100011001011011100101100110100110010110100010011010110011010010010110100100110010011001011001101001011001101001?110100101100011010011001011001101001011011?01001011010000101100110100101101100110101100110100101101001100101100110010110011011000011011001011000011010010110100101100111001011001...

output:

165248
67
67800
12312
6642
173728
129888
3724
44680
59112
343
2285
2628
356640
5150
74520
651
7544
2299
23680
32548
3908
3919
337952
682
119008
123024
276
13148
33452
8254
70552
7082
799
10000
734
170048
367136
1470
398
2127
14100
763
182688
350560
804
62088
10108
365472
16168
11136
66
2347
56664
15...

result:

ok 1000 numbers

Test #36:

score: 5
Accepted
time: 2454ms
memory: 330796kb

input:

500 1000
0110100110010110100101?00110100101101001100101100101101001100101100110100110010110101001011001101010100?100101101001011001101001100101100110100101101001100101101001011001101001011010011001011001101001100101101001011001101001100?0110011010110100110010110011010010110?001100101100110?001100101...

output:

393
233816
97288
178160
157752
521488
7155
2230
429616
78500
29384
192248
13936
22126
1952
103352
547504
165400
722032
39936
6616
1335584
3086016
65036
278
91692
619024
96060
62792
198512
642160
20596
627120
16676
1248096
356616
4303
79340
229120
570368
28
5047
11090
36716
1276320
1454432
17460
1160...

result:

ok 1000 numbers

Subtask #7:

score: 0
Runtime Error

Test #37:

score: 0
Runtime Error

input:

1000 2000
01100101101001011001101001011010011001011010010110011010011001011001101001011010011001011010010110011010000110100101101001100101100110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100101101001100101101001011001101001...

output:


result:


Subtask #8:

score: 0
Runtime Error

Test #43:

score: 0
Runtime Error

input:

5000 100000
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:


result:


Subtask #9:

score: 0
Runtime Error

Test #49:

score: 0
Runtime Error

input:

20000 100000
????????????????????????????0??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:


result:


Subtask #10:

score: 0
Runtime Error

Test #55:

score: 0
Runtime Error

input:

50000 200000
?01101001011001?01?011?010?1001101001?110?001?0?1?1?001101?0110?101?010??01100110?00?1001011001101001011??001?001?110100101100110100101?01?0110?1011?011010011001?1?0100??110011?100?01101001100?011010?10??00110100?1?0?0110?1101?01??1?10??10010?10?00101?00??0???101101?0???010110??1?10011?...

output:


result: