QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#783340#9639. 字符串zjy0001100 ✓532ms277676kbC++172.9kb2024-11-26 08:36:012024-11-26 08:36:02

Judging History

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

  • [2024-11-26 08:36:02]
  • 评测
  • 测评结果:100
  • 用时:532ms
  • 内存:277676kb
  • [2024-11-26 08:36:01]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=5e5+5;
int typ,n,q;
char s[N];
int ans[N],c[N];
vector<tuple<int,int,int>>E;
int sa[N],rk[N],height[N],nxt[N];
vector<pair<int,int>>Q[N],nQ[N],A[N];
inline void add(int x,int y){
	for(;x<=n;x+=x&-x)c[x]+=y;
}
inline int sum(int x){
	int z=0;for(;x;x-=x&-x)z+=c[x];return z;
}
template<class T>inline void SA(T* s,int n){
	static int t1[N],t2[N],cnt[N];
	int *x=t1,*y=t2,m=128;
	for(int i=1;i<=n;++i)++cnt[x[i]=s[i]];
	for(int i=1;i<=m;++i)cnt[i]+=cnt[i-1];
	for(int i=n;i>=1;--i)sa[cnt[x[i]]--]=i;
	fill(cnt,cnt+m+1,0);
	for(int k=1;;k<<=1){
		int p=0;
		for(int i=n-k+1;i<=n;++i)y[++p]=i;
		for(int i=1;i<=n;++i)if(sa[i]>k)y[++p]=sa[i]-k;
		for(int i=1;i<=n;++i)++cnt[x[i]];
		for(int i=1;i<=m;++i)cnt[i]+=cnt[i-1];
		for(int i=n;i>=1;--i)sa[cnt[x[y[i]]]--]=y[i],y[i]=0;
		fill(cnt,cnt+m+1,0);
		swap(x,y),x[sa[p=1]]=1;
		for(int i=2;i<=n;++i)
			x[sa[i]]=p=p+1-(y[sa[i]]==y[sa[i-1]]&&(sa[i]+k<=n?y[sa[i]+k]:0)==(sa[i-1]+k<=n?y[sa[i-1]+k]:0));
		if((m=p)>=n)break;
	}
	for(int i=1;i<=n;++i)rk[sa[i]]=i;
	for(int i=1,j=0;i<=n;++i){
		j=max(j-1,0);
		if(rk[i]==1)continue;
		int k=sa[rk[i]-1];
		while(i+j<=n&&j+k<=n&&s[i+j]==s[j+k])++j;
		height[rk[i]]=j;
	}
}
template<class T>inline void Z(T* s,int n){
	nxt[1]=n;
    for(int i=2,j=0,k=0;i<=n;++i){
        nxt[i]=max(min(k-i,nxt[i-j+1]),0);
        for(;i+nxt[i]<=n&&s[nxt[i]+1]==s[i+nxt[i]];++nxt[i]);
        if(i+nxt[i]>k)j=i,k=i+nxt[i];
    }
}
inline vector<int>Z(string s){
	const int n=s.length();
	s=" "+s,Z(s.c_str(),n);
	return vector<int>(nxt+1,nxt+n+1);
}
inline void solve(int l,int r){
	if(l==r)return;
	const int mid=(l+r)>>1;
	solve(l,mid),solve(mid+1,r);
	string u(s+l,s+mid+1),v(s+mid+1,s+r+1),ru(u.rbegin(),u.rend()),rv(v.rbegin(),v.rend());
	auto zx=Z(ru+'#'+rv),zy=Z(v+'#'+u);
	for(int i=0;i<r-l+1;++i){
		int p,k1,k2;
		if(i<mid-l+1)p=mid-l+1-i,k1=zx[p],k2=zy[r-mid+1+i];
		else p=i-(mid-l+1)+1,k1=zx[r-l+1-(p-1)],k2=zy[p];
		if(k1+k2>=p){
			if(i<mid-l+1){
				int x=max(1,p-k2),y=min(p,k1);
				if(y==p)--y;
				if(x<=y)E.emplace_back(l+i-y,l+i-x,p);
			}
			else{
				int x=max(1,p-k2),y=min(p,k1);
				if(x<=y)E.emplace_back(l+i-p+1-y,l+i-p+1-x,p);
			}
		}
	}
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
	cin>>typ;
	cin>>n>>q>>(s+1);
	SA(s,n);
	for(int i=1;i<=q;++i){
		int x,r;cin>>x>>r;
		Q[x].emplace_back(r,i);
		nQ[r].emplace_back(x,i);
	}
	for(int i=n;i>=1;--i){
		const int x=sa[i];
		for(auto [r,id]:Q[x])ans[id]+=sum(x+r)-sum(x);
		add(x,1);
	}
	solve(1,n);
	for(auto [x,y,l]:E)if(rk[y]<rk[y+l])A[l].emplace_back(x,y);
	fill_n(c+1,n,0);
	for(int i=1;i<=n;++i){
		for(auto [l,r]:A[i])add(l,1),add(r+1,-1);
		for(auto [x,id]:nQ[i])ans[id]-=sum(x);
	}
	for(int i=1;i<=q;++i)cout<<ans[i]<<'\n';
    return 0;
}
/*
*/

詳細信息

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 8ms
memory: 57096kb

input:

1
5000 5000
babbbabbbaabbaaabaaababbbaaabbabbbaabbabbabbbaaaabbaaabbbbbaabbbaababbaaaabaababbabbbbbbababaaaaabaabbaabbabaaababbbbaaababaabbbababbbbaaaaaabbaaaaaabaabbbbaabbbbbbabbabbbaabbabbbabbabbabababbaabbaabbababbaaaaabbabaaabbbabbbabaabbabbabaaaaaabbaababbbababbabbaababaababbbbbabbbbaabaabbaabb...

output:

943
901
504
8
1599
40
650
268
32
324
1010
686
10
225
71
40
48
306
260
498
1487
969
107
20
57
14
200
167
10
108
506
126
440
69
171
52
59
271
13
429
83
415
911
101
694
893
1099
457
585
129
295
54
43
516
405
1200
292
729
253
7
25
927
11
245
23
528
54
469
245
79
6
46
403
105
76
735
0
0
320
48
559
1272
1...

result:

ok 5000 lines

Test #2:

score: 20
Accepted
time: 13ms
memory: 56620kb

input:

1
5000 5000
babbbabbbaabbaaabaaababbbaaabbabbbaabbabbabbbaaaabbaaabbbbbaabbbaababbaaaabaababbabbbbbbababaaaaabaabbaabbabaaababbbbaaababaabbbababbbbaaaaaabbaaaaaabaabbbbaabbbbbbabbabbbaabbabbbabbabbabababbaabbaabbababbaaaaabbabaaabbbabbbabaabbabbabaaaaaabbaababbbababbabbaababaababbbbbabbbbaabaabbaabb...

output:

943
901
504
8
1599
40
650
268
32
324
1010
686
10
225
71
40
48
306
260
498
1487
969
107
20
57
14
200
167
10
108
506
126
440
69
171
52
59
271
13
429
83
415
911
101
694
893
1099
457
585
129
295
54
43
516
405
1200
292
729
253
7
25
927
11
245
23
528
54
469
245
79
6
46
403
105
76
735
0
0
320
48
559
1272
1...

result:

ok 5000 lines

Test #3:

score: 20
Accepted
time: 10ms
memory: 56224kb

input:

1
5000 5000
babbbabbbaabbaaabaaababbbaaabbabbbaabbabbabbbaaaabbaaabbbbbaabbbaababbaaaabaababbabbbbbbababaaaaabaabbaabbabaaababbbbaaababaabbbababbbbaaaaaabbaaaaaabaabbbbaabbbbbbabbabbbaabbabbbabbabbabababbaabbaabbababbaaaaabbabaaabbbabbbabaabbabbabaaaaaabbaababbbababbabbaababaababbbbbabbbbaabaabbaabb...

output:

943
901
504
8
1599
40
650
268
32
324
1010
686
10
225
71
40
48
306
260
498
1487
969
107
20
57
14
200
167
10
108
506
126
440
69
171
52
59
271
13
429
83
415
911
101
694
893
1099
457
585
129
295
54
43
516
405
1200
292
729
253
7
25
927
11
245
23
528
54
469
245
79
6
46
403
105
76
735
0
0
320
48
559
1272
1...

result:

ok 5000 lines

Test #4:

score: 20
Accepted
time: 8ms
memory: 56380kb

input:

1
5000 5000
babbbabbbaabbaaabaaababbbaaabbabbbaabbabbabbbaaaabbaaabbbbbaabbbaababbaaaabaababbabbbbbbababaaaaabaabbaabbabaaababbbbaaababaabbbababbbbaaaaaabbaaaaaabaabbbbaabbbbbbabbabbbaabbabbbabbabbabababbaabbaabbababbaaaaabbabaaabbbabbbabaabbabbabaaaaaabbaababbbababbabbaababaababbbbbabbbbaabaabbaabb...

output:

943
901
504
8
1599
40
650
268
32
324
1010
686
10
225
71
40
48
306
260
498
1487
969
107
20
57
14
200
167
10
108
506
126
440
69
171
52
59
271
13
429
83
415
911
101
694
893
1099
457
585
129
295
54
43
516
405
1200
292
729
253
7
25
927
11
245
23
528
54
469
245
79
6
46
403
105
76
735
0
0
320
48
559
1272
1...

result:

ok 5000 lines

Test #5:

score: 20
Accepted
time: 8ms
memory: 55488kb

input:

1
5000 5000
aababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaab...

output:

1
9
558
232
344
137
258
39
21
98
25
997
127
132
1017
11
34
360
24
103
26
98
65
23
254
27
752
1124
164
89
8
365
103
108
19
58
1
272
626
20
70
94
14
275
1072
103
254
29
1
89
14
1
217
267
490
355
590
88
216
403
103
812
1160
32
504
104
371
618
89
1562
92
186
186
535
2046
519
43
263
346
154
72
885
397
38...

result:

ok 5000 lines

Subtask #2:

score: 10
Accepted

Test #6:

score: 10
Accepted
time: 84ms
memory: 59244kb

input:

2
100000 100000
aabaababababbabbbbaaaaabbabaaaaabaaaabbbbaaaaaabbabbaaabaababaaaaaaabaabbbabbaabaabaababbbbbbaaabbabbaabaabbaaabbbaaaabaabbaababbaaabbabbababaaababaababbabbbababbaaaaababbaaaabbaaabbbbabaaabbbbaaaabbabbabbaaaaaabbabbbaaaabbaabbbaaabaabaabbbaaabaababaabaaabbaaabbbaaababaabbbabaabbaaab...

output:

336
1019
15080
9970
20317
696
8784
3375
387
772
780
1661
35
2789
21136
204
18031
196
5786
225
250
10232
467
8783
9732
9644
981
272
3123
9848
980
39088
859
219
1255
15559
2887
3832
5515
12622
286
4643
86
8618
1911
2013
1404
10970
10377
219
2011
116
363
14044
12832
14673
1194
9829
13505
14448
12333
11...

result:

ok 100000 lines

Test #7:

score: 10
Accepted
time: 80ms
memory: 60856kb

input:

2
100000 100000
aabaababababbabbbbaaaaabbabaaaaabaaaabbbbaaaaaabbabbaaabaababaaaaaaabaabbbabbaabaabaababbbbbbaaabbabbaabaabbaaabbbaaaabaabbaababbaaabbabbababaaababaababbabbbababbaaaaababbaaaabbaaabbbbabaaabbbbaaaabbabbabbaaaaaabbabbbaaaabbaabbbaaabaabaabbbaaabaababaabaaabbaaabbbaaababaabbbabaabbaaab...

output:

336
1019
15080
9970
20317
696
8784
3375
387
772
780
1661
35
2789
21136
204
18031
196
5786
225
250
10232
467
8783
9732
9644
981
272
3123
9848
980
39088
859
219
1255
15559
2887
3832
5515
12622
286
4643
86
8618
1911
2013
1404
10970
10377
219
2011
116
363
14044
12832
14673
1194
9829
13505
14448
12333
11...

result:

ok 100000 lines

Test #8:

score: 10
Accepted
time: 91ms
memory: 60680kb

input:

2
100000 100000
aaaababaabaaabbaaabbaaaabbaababbaaaabaabbbbbbbbabbbabbbbabbabaaaaabaabaaabaaababbbaaabbbaabbaaabbaabbbbaaaaababaabaaaabababaabbaaabaabbbbbaaaaabbaabaaaaaaaaababababaabbabbbabbbbbaabbbbbabbaababbbbbbababbaababbabaabbbbaaaaabaabbaaabbbbbbbaabbbaaabaaaabaabaaaaabbbbbbbbaabaabababbbbbaba...

output:

11772
1819
14389
905
105
1917
1858
666
11413
1863
993
3113
280
9852
752
2232
2806
3126
14696
2857
17489
11291
1523
1629
745
2920
5884
4070
24943
1551
3576
2062
101
1045
138
8859
8389
2154
2118
2507
2
614
8468
12229
3499
19139
14
2222
8612
0
10253
25661
2822
6752
4
6314
1645
2632
6014
429
5539
2903
2...

result:

ok 100000 lines

Test #9:

score: 10
Accepted
time: 89ms
memory: 59188kb

input:

2
100000 100000
aaaababaabaaabbaaabbaaaabbaababbaaaabaabbbbbbbbabbbabbbbabbabaaaaabaabaaabaaababbbaaabbbaabbaaabbaabbbbaaaaababaabaaaabababaabbaaabaabbbbbaaaaabbaabaaaaaaaaababababaabbabbbabbbbbaabbbbbabbaababbbbbbababbaababbabaabbbbaaaaabaabbaaabbbbbbbaabbbaaabaaaabaabaaaaabbbbbbbbaabaabababbbbbaba...

output:

11772
1819
14389
905
105
1917
1858
666
11413
1863
993
3113
280
9852
752
2232
2806
3126
14696
2857
17489
11291
1523
1629
745
2920
5884
4070
24943
1551
3576
2062
101
1045
138
8859
8389
2154
2118
2507
2
614
8468
12229
3499
19139
14
2222
8612
0
10253
25661
2822
6752
4
6314
1645
2632
6014
429
5539
2903
2...

result:

ok 100000 lines

Test #10:

score: 10
Accepted
time: 93ms
memory: 59268kb

input:

2
100000 100000
baaabaababbbbababaabababaaaabbaabaaabbaababaabbababaababbbbabaababaabbbbbbbabbbabbbbaabaaaababbbabbbbabaaaaabbbbbbaabbabaabaaaaaababaabbababbaaaabbabbbaaaabbbaababbbbabababababbabababbbbbaaabaabaaaabbbbabbaaababbabaaaaaabaabaabaaabaaaababaabbbaaaabababbaababaabbbaababaaaabbbbabbabbba...

output:

13912
6871
396
11429
5191
21624
3028
11883
12
1081
7279
1326
2162
21687
1775
9790
6245
365
805
25
15887
3030
6427
266
11962
662
4066
244
1037
1358
2787
27389
4225
13
4580
732
2181
5733
15532
3364
4709
5599
1058
2650
2078
8716
2506
12220
2568
7882
3940
13505
2877
465
5402
6654
2363
2925
439
228
646
7...

result:

ok 100000 lines

Subtask #3:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #11:

score: 20
Accepted
time: 85ms
memory: 61096kb

input:

3
100000 100000
aababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaaba...

output:

15634
7997
23631
523
322
8807
727
1658
198
6346
3354
4266
281
10007
4656
2198
3519
3337
1584
1618
7646
3886
7250
11029
813
753
8
4134
1172
6052
30867
6520
2515
657
14358
6005
1025
4432
1217
9380
2281
6890
108
2642
7208
238
940
13150
6217
1037
268
163
582
2887
2439
102
98
2502
6469
3738
966
17297
768...

result:

ok 100000 lines

Test #12:

score: 20
Accepted
time: 88ms
memory: 59620kb

input:

3
100000 100000
aababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbcc...

output:

6735
5554
4932
6897
1706
18283
15155
2355
1511
3098
10347
521
267
9513
21
3655
3359
1356
192
93
19422
2072
26942
3223
7272
5534
7539
4153
7000
11434
4760
676
8655
85
10
2515
1390
47
3182
401
5917
514
4780
9234
2298
2150
1911
3182
12865
14841
2849
956
4624
4246
1419
266
852
12934
63
267
29359
3921
33...

result:

ok 100000 lines

Test #13:

score: 20
Accepted
time: 69ms
memory: 60012kb

input:

3
100000 100000
ghbaahxvveloseywqeuokpraqgyscdcimfioohjjnwyhdyftczjorapjhncjqetfjetxnfidbgkeesajrjxkkmutayescxxndtmryuubdgijyisstqefcayeycxccwpfpdypautdbbmblfvexakzakgzpfdrdtytyzkytfdwgqarxvyuvivysbzhgcakxbfwarwvxaufsuzprxjnhenbimlqoncmojkqbgoaiifaegpvdakmhxoplzfamkodtatwghwprerxkhtqhfcofqfqrnsgxgjs...

output:

6291
1292
2790
2079
133
4509
451
555
5305
435
15144
2701
8544
16797
4460
1891
526
16938
4753
8881
27
4775
3227
164
1511
14286
751
1071
2848
5141
9515
2339
7586
778
2651
13216
154
15420
3178
13033
5770
5891
5347
146
45
5184
409
2084
4105
8608
12128
7267
342
3514
13802
754
11528
7547
12211
1570
10008
...

result:

ok 100000 lines

Test #14:

score: 20
Accepted
time: 82ms
memory: 83752kb

input:

3
100000 100000
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #15:

score: 20
Accepted
time: 81ms
memory: 62352kb

input:

3
100000 100000
aababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaaba...

output:

3046
5650
394
5764
2987
13467
11480
275
5719
3499
10592
13695
13657
14050
7130
129
6853
1712
2986
2009
11408
6009
1303
11714
2163
9699
5439
3567
5984
24867
8352
1944
10664
800
14750
5646
1181
667
22
2772
7613
1679
2002
3481
5836
22660
108
3326
54
808
2759
5247
1016
4390
1519
4999
19160
21745
1155
11...

result:

ok 100000 lines

Subtask #4:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #3:

100%
Accepted

Test #16:

score: 20
Accepted
time: 273ms
memory: 75504kb

input:

4
300000 300000
babaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbaba...

output:

2127
17628
11541
14729
2054
49773
14238
911
18758
84206
19471
59591
124
45510
3234
17188
3632
20561
5997
17371
6432
46510
7140
11771
9403
59
12453
201
2197
10207
10739
18259
11655
523
36622
10838
190
10929
3343
20748
46234
50831
12051
8562
32727
33481
45892
50476
59553
1445
22781
4553
59
4009
6868
1...

result:

ok 300000 lines

Test #17:

score: 20
Accepted
time: 288ms
memory: 74236kb

input:

4
300000 300000
bbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbc...

output:

16550
7982
1799
18514
20159
295
20356
410
7584
2046
9198
5576
10356
20360
2777
4696
48509
839
19660
39715
56
128
15924
956
9487
16050
957
763
972
1645
8257
69650
57161
929
34540
583
21312
15344
13453
1525
345
302
35316
11776
2612
10012
15980
694
2436
11149
2270
1437
2644
58861
23578
85930
1400
40744...

result:

ok 300000 lines

Test #18:

score: 20
Accepted
time: 245ms
memory: 70636kb

input:

4
300000 300000
hpdtaorltsivwlbqykwotvvbydvnnxyupdqprjanckiavlquynkrkhvklsxaqxvfbnuuwwhaircedtabikusupefiefabcherbzozgqhatnfongwacquswbcaiecllgcofsnolwqgkvwzdszfkvzgwbhhhlusrygzrvpeuhmgciffchkmckubndixocpiawjttaznhlvltbqvkcjmogpejzbabqkeovzkvzzemvpgyhdijpwavoegnhirzsvqpuamvbqiwhqwovgakfchtiqgpaxqtug...

output:

48782
18911
1037
60895
14064
1750
17959
13154
2530
2808
6488
68863
2750
1977
12479
4094
1803
47027
3073
4712
7513
41256
24992
87936
101680
1097
9217
25999
13342
30741
24190
65219
334
18849
2740
2369
1712
49
74162
102866
23094
11117
2716
16603
50709
33378
47896
3491
15696
10177
9875
522
5235
9608
523...

result:

ok 300000 lines

Test #19:

score: 20
Accepted
time: 280ms
memory: 166580kb

input:

4
300000 300000
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 300000 lines

Test #20:

score: 20
Accepted
time: 279ms
memory: 75092kb

input:

4
300000 300000
ababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbcca...

output:

34478
21636
63153
7070
5075
58660
4710
18698
24818
42188
41996
48057
5124
2015
5514
15605
12923
27550
23297
3364
5
3119
38606
12171
11422
20251
768
17625
2331
3205
16303
29386
2831
65531
10142
3180
6
11952
25059
2201
49385
2012
35389
1821
38904
143
80110
2602
874
11171
12399
507
20392
357
17768
2930...

result:

ok 300000 lines

Subtask #5:

score: 30
Accepted

Dependency #1:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #21:

score: 30
Accepted
time: 532ms
memory: 90244kb

input:

5
500000 500000
babbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababb...

output:

45676
114315
1373
5470
58733
541
58335
76940
12171
1289
1296
5981
46695
60474
5998
6354
17365
1598
47943
738
52953
437
670
12273
3148
2914
124917
20950
65156
8542
12460
1040
441
32021
128532
33762
1025
79163
6102
6450
70058
3973
74663
1235
6167
3904
11080
32073
59
25326
6334
90624
40639
20111
66336
...

result:

ok 500000 lines

Test #22:

score: 30
Accepted
time: 522ms
memory: 86168kb

input:

5
500000 500000
aababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbcc...

output:

3035
8094
49867
64879
21516
41407
7401
1010
1934
1038
16997
255
2691
32729
39342
9664
74201
23020
21273
11422
2059
160983
85041
21862
646
3479
70389
85729
81026
5840
388
89763
12747
75217
72787
89910
10232
166
144054
33602
11280
70147
150496
82
15453
4186
1602
92023
7118
12301
66564
17871
5935
13786...

result:

ok 500000 lines

Test #23:

score: 30
Accepted
time: 466ms
memory: 277536kb

input:

5
500000 500000
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 500000 lines

Test #24:

score: 30
Accepted
time: 480ms
memory: 277676kb

input:

5
500000 500000
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 500000 lines

Test #25:

score: 30
Accepted
time: 508ms
memory: 91052kb

input:

5
500000 500000
babbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababb...

output:

3813
22449
40874
28936
2873
15071
71086
57461
38081
13917
55914
12050
73696
3188
41751
31930
7822
36947
276
1785
29201
5083
12097
1922
32999
6102
24512
107193
81504
3676
7039
32037
28339
107479
73196
89293
117847
26567
5529
2705
64024
1008
4589
148395
108627
578
7946
871
21915
4453
22591
112894
33
8...

result:

ok 500000 lines