QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#389478#6842. Popcount WordsoscaryangWA 476ms422584kbC++172.4kb2024-04-14 14:26:372024-04-14 14:26:38

Judging History

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

  • [2024-04-14 14:26:38]
  • 评测
  • 测评结果:WA
  • 用时:476ms
  • 内存:422584kb
  • [2024-04-14 14:26:37]
  • 提交

answer

#include<bits/stdc++.h>

#define vc vector
#define pb emplace_back
#define pii pair<int, int>
#define mkp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define lep(i, a, b) for(int i = (a); i >= (b); --i)

#define int long long

using namespace std;

mt19937 gen(time(0));

inline int read() {
	int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x; 
}

const int N = 2e6 + 5, LOG = 22;

int n, m;
int f[N][LOG][2], g[N][LOG][2], pos[N], sum[N];
char str[N];
vc <pii> S;

namespace acam {
	int ch[N][2], fail[N], idx = 1, rt = 1;
	vc <int> G[N];	
	inline int ins (char *s, int n) {
		int x = rt;
		for (int i = 1, c; i <= n; i++, x = ch[x][c]) 
			if (!ch[x][c = s[i] - '0']) ch[x][c] = ++idx;
		return x;
	}
	inline void build () {
		queue <int> Q;
		rep (i, 0, 1) 
			if (ch[rt][i]) fail[ch[rt][i]] = rt, Q.push (ch[rt][i]); 
			else ch[rt][i] = rt;
		while (!Q.empty ()) {
			int x = Q.front (); Q.pop ();
			rep (i, 0, 1) 
				if (ch[x][i]) fail[ch[x][i]] = ch[fail[x]][i], Q.push (ch[x][i]);
				else ch[x][i] = ch[fail[x]][i];
		}
		rep (i, 2, idx) G[fail[i]].pb (i);
	}
	inline void dfs (int x) {
		sum[x] += g[x][0][0] + g[x][0][1];
		for (auto y : G[x]) dfs (y), sum[x] += sum[y];
	}
}
using namespace acam;

inline void collect (int l, int r, int L, int R, int d, int s = 0) {
	if (L > R || L > r || R < l) return ;
	if (L <= l && R >= r) return S.pb (mkp (d, s)), void ();
	int mid = l + r >> 1;
	collect (l, mid, L, R, d - 1, s); collect (mid + 1, r, L, R, d - 1, s ^ 1);
}

signed main() {
	n = read(); m = read(); 
	
	for (int i = 1, l, r; i <= n; i++) 
		l = read(), r = read(), collect (0, (1ll << 31) - 1, l, r, 31);
	
	for (int i = 1, l; i <= m; i++) {
		scanf ("%s", str + 1); l = strlen (str + 1);
		pos[i] = ins (str, l);
	}
	acam :: build ();
	
	rep (i, 1, idx) rep (j, 0, 1) f[i][0][j] = ch[i][j];
	rep (i, 1, LOG - 1) rep (x, 1, idx) rep (j, 0, 1) 
		f[x][i][j] = f[f[x][i - 1][j]][i - 1][1 - j];
	// match 
	{
		int x = rt; 
		for (auto [u, v] : S) ++g[x][u][v], x = f[x][u][v];
		++sum[x];
	}
	lep (i, LOG - 1, 1) rep (x, 1, idx) rep (j, 0, 1) 
		g[x][i - 1][j] += g[x][i][j], g[f[x][i - 1][j]][i - 1][1 - j] += g[x][i][j];
	dfs (rt);
	
	rep (i, 1, m) printf ("%lld\n", sum[pos[i]]);
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 5
2 6
1 3
4 8
0
1
11
101
0011010

output:

6
7
2
2
1

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 50784kb

input:

3 10
2 6
1 3
4 8
0
1
11
101
0011010
0
1
11
101
0011010

output:

6
7
2
2
1
6
7
2
2
1

result:

ok 10 lines

Test #3:

score: 0
Accepted
time: 59ms
memory: 82188kb

input:

100000 37701
605224571 605224571
681034454 681034463
468837041 468837048
323235128 323235135
400367345 400367345
394938241 394938241
221026001 221026007
183872918 183872926
881878131 881878138
374491962 374491967
588030380 588030381
109143398 109143401
727016146 727016149
857189138 857189138
1940312...

output:

273828
273405
99633
174195
174195
99209
16229
83404
91124
83071
83404
90791
83070
16138
3449
12780
43045
40359
43221
47903
70380
12690
12780
70624
48079
42712
40183
42887
12690
3448
413
3036
6576
6204
11678
31367
34167
6191
6484
36737
16633
31270
33957
36423
9697
2993
3036
9744
36469
34155
31543
165...

result:

ok 37701 lines

Test #4:

score: 0
Accepted
time: 467ms
memory: 403988kb

input:

100000 2064
155864032 155864033
351106162 351106162
63569309 63569310
446198383 446198387
844050143 844050148
28666643 28666652
948049121 948049128
422938918 422938925
590576664 590576664
118827333 118827339
248813547 248813549
222041903 222041911
481862624 481862626
39190429 39190429
373420004 3734...

output:

274777
274799
99973
174803
174803
99996
16241
83732
91053
83750
83732
91070
83750
16246
3457
12784
43222
40510
43091
47961
70993
12757
12784
70948
47831
43239
40641
43109
12757
3489
459
2998
6565
6219
11607
31614
34345
6165
6467
36624
16421
31540
34510
36483
9693
3064
2998
9786
36657
34291
31484
163...

result:

ok 2064 lines

Test #5:

score: 0
Accepted
time: 448ms
memory: 420512kb

input:

100000 264
863548123 863548131
726674730 726674731
23567654 23567655
388640944 388640951
11253180 11253185
364951459 364951461
954258329 954258336
370336558 370336567
783663445 783663448
948622704 948622711
241717161 241717163
167305985 167305985
559579744 559579746
686340873 686340882
110381066 110...

output:

275122
274500
100192
174929
174929
99571
16458
83734
91338
83591
83734
91194
83591
15980
3543
12915
43156
40578
43255
48082
70962
12629
12915
70819
48181
43013
40479
43112
12629
3351
482
3061
6476
6439
11559
31596
34378
6200
6644
36611
16564
31518
34274
36688
9720
2909
3061
9854
36680
34139
31696
16...

result:

ok 264 lines

Test #6:

score: 0
Accepted
time: 447ms
memory: 422584kb

input:

100000 82
440580187 440580195
363746917 363746923
253327641 253327648
77285448 77285454
16654500 16654506
701949354 701949357
335798407 335798407
510898124 510898124
728200505 728200507
657089802 657089806
811878897 811878897
740279233 740279234
2002051 2002056
201584556 201584557
905281625 90528163...

output:

274946
275169
99944
175001
175001
100168
16163
83781
91017
83984
83781
91219
83984
16184
3463
12700
42944
40837
42987
48029
71306
12678
12700
71081
48072
43147
40794
43190
12678
3506
483
2980
6395
6305
11456
31487
34601
6236
6440
36547
16623
31406
34670
36636
9614
3064
2980
9720
36549
34532
31531
16...

result:

ok 82 lines

Test #7:

score: 0
Accepted
time: 430ms
memory: 421576kb

input:

100000 65
990903704 990903704
488837026 488837029
520610697 520610700
84740156 84740158
145465213 145465219
802621365 802621370
637129208 637129216
138040766 138040770
789708694 789708702
122215439 122215439
805389806 805389815
726116821 726116826
90711329 90711332
980579500 980579500
877100759 8771...

output:

275313
275152
100356
174957
174957
100194
16549
83807
90996
83960
83807
91150
83961
16233
3570
12979
43006
40801
43164
47832
71205
12755
12979
70828
47990
43159
40643
43318
12755
3478
456
3114
6506
6473
11758
31248
34498
6303
6609
36555
16430
31401
34399
36806
9714
3041
3114
9865
36500
34328
31406
1...

result:

ok 65 lines

Test #8:

score: 0
Accepted
time: 476ms
memory: 420112kb

input:

100000 15
622051406 622051410
809727709 809727711
305371768 305371773
184626015 184626015
485560137 485560143
683120615 683120618
494143101 494143106
820622384 820622384
428188273 428188280
192875194 192875198
420425386 420425394
692993018 692993020
892081956 892081958
149770059 149770067
971481390 ...

output:

274897
275773
99624
175272
175273
100500
16106
83518
91087
84185
83518
91754
84185
16315
1

result:

ok 15 lines

Test #9:

score: -100
Wrong Answer
time: 80ms
memory: 120492kb

input:

100000 37701
22481700 108517447
365920329 760528107
176789774 293610871
626946693 749768996
176851510 945414284
28086800 69412398
975208777 978832901
602518142 777697473
926108743 981817845
102894249 424879855
807095920 982351889
387442755 443766483
240971703 255490115
877218778 889992331
212556206 ...

output:

206747055484
206747057801
68915697585
137831357899
137831357898
68915699902
16685
68915680900
68915674788
68915683110
68915680899
68915676999
68915683110
16792
2838
13847
34457841676
34457839223
34457842884
34457831904
68915669153
13957
13847
68915667052
34457833112
34457843887
34457838015
344578450...

result:

wrong answer 1st lines differ - expected: '12456513055026', found: '206747055484'