QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#783620#9639. 字符串Nesraychan100 ✓627ms166464kbC++143.1kb2024-11-26 11:04:052024-11-26 11:04:19

Judging History

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

  • [2024-11-26 11:04:19]
  • 评测
  • 测评结果:100
  • 用时:627ms
  • 内存:166464kb
  • [2024-11-26 11:04:05]
  • 提交

answer

#include<bits/stdc++.h>
#define IL inline
#define reg register
#define N 500500
IL int read()
{
    reg int x=0,f=0; reg char ch=getchar();
    while(ch<'0'||ch>'9')f|=ch=='-',ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return f?-x:x;
}

int n,q;
char s[N],t[N];

struct Suffix_Array
{
    int sa[N],rk[N],x[N],y[N],buc[N],m,tot,st[20][N],*h=st[0];

    IL int min(reg int x,reg int y){return x<y?x:y;}

    IL int lcp(reg int x,reg int y)
    {
        if(x==y)return n-x+1;
        x=rk[x],y=rk[y];
        if(x>y)std::swap(x,y);
        ++x;
        reg int o=std::__lg(y-x+1);
        return min(st[o][x],st[o][y-(1<<o)+1]);
    }

    IL void init(char *s)
    {
        m='z';
        for(reg int i=1;i<=n;++i)++buc[x[i]=s[i]];
        for(reg int i=1;i<=m;++i)buc[i]+=buc[i-1];
        for(reg int i=n;i;--i)sa[buc[x[i]]--]=i;
        for(reg int k=1,i;;k<<=1)
        {
            tot=0;
            for(i=n;i>n-k;--i)y[++tot]=i;
            for(i=1;i<=n;++i)if(sa[i]>k)y[++tot]=sa[i]-k;
            for(i=1;i<=m;++i)buc[i]=0;
            for(i=1;i<=n;++i)++buc[x[i]];
            for(i=1;i<=m;++i)buc[i]+=buc[i-1];
            for(i=n;i;--i)sa[buc[x[y[i]]]--]=y[i];
            for(i=1;i<=n;++i)y[i]=x[i];
            x[sa[1]]=1;
            for(i=2;i<=n;++i)x[sa[i]]=x[sa[i-1]]+(y[sa[i]]!=y[sa[i-1]]||y[sa[i]+k]!=y[sa[i-1]+k]);
            if((m=x[sa[n]])==n)break;
        }
        for(reg int i=1;i<=n;++i)rk[i]=x[i];
        for(reg int i=1,j,k=0;i<=n;++i)if(rk[i]>1)
        {
            if(k)--k; j=sa[rk[i]-1];
            while(s[i+k]==s[j+k])++k;
            h[rk[i]]=k;
        }
        for(reg int o=1,i;o<20;++o)for(i=1;i+(1<<o)-1<=n;++i)
            st[o][i]=min(st[o-1][i],st[o-1][i+(1<<o-1)]);
    }
}A,B;

IL void cmin(reg int &x,reg int y){x>y?x=y:0;}
IL void cmax(reg int &x,reg int y){x<y?x=y:0;}

int ans[N];
std::vector<std::pair<int,int>>vec1[N],vec2[N],shelf[N];
int c[N];

IL int low(reg int x){return x&-x;}
IL int ask(reg int x){reg int r=0; for(;x;x-=low(x))r+=c[x]; return r;}
IL void add(reg int x,reg int k){for(;x<=n;x+=low(x))c[x]+=k;}
IL void clear(){std::fill(c+1,c+1+n,0);}

main()
{
    read(),n=read(),q=read();
    scanf("%s",s+1);
    for(reg int i=1;i<=n;++i)t[n-i+1]=s[i];
    A.init(s),B.init(t);
    for(reg int k=1,i,j,l,r,p;k<=n;++k)for(i=k,j=k+k;j<=n;i+=k,j+=k)
    {
        l=i+1,r=j;
        p=B.lcp(n-i+1,n-j+1),cmax(l,j-p+1);
        p=A.lcp(i,j),cmin(r,j+p-k);
        if(l<=r&&A.rk[r-k]<A.rk[r])
            shelf[l-k].push_back({k,1}),shelf[r-k+1].push_back({k,-1});
    }
    for(reg int i=1,x,k;i<=q;++i)
    {
        x=read(),k=read();
        vec1[x].push_back({k,i});
        vec2[x].push_back({k,i});
    }
    for(reg int i=1;i<=n;++i)
    {
        for(auto &[x,k]:shelf[i])add(x,k);
        for(auto &[x,id]:vec1[i])ans[id]=-ask(x);
    }
    clear();
    for(reg int i=n,x;i;--i)
    {
        add(x=A.sa[i],1);
        for(auto &[k,id]:vec2[x])
            ans[id]+=ask(x+k)-ask(x);
    }
    for(reg int i=1;i<=q;++i)printf("%d\n",ans[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 3ms
memory: 72260kb

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: 4ms
memory: 64148kb

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: 12ms
memory: 64056kb

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: 6ms
memory: 64276kb

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: 6ms
memory: 45924kb

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: 58ms
memory: 65312kb

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: 68ms
memory: 67236kb

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: 69ms
memory: 68852kb

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: 71ms
memory: 83752kb

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: 65ms
memory: 84832kb

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: 74ms
memory: 84964kb

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: 74ms
memory: 85528kb

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: 50ms
memory: 83456kb

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: 73ms
memory: 83192kb

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: 78ms
memory: 88308kb

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: 323ms
memory: 127672kb

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: 319ms
memory: 126672kb

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: 198ms
memory: 120740kb

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: 221ms
memory: 120392kb

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: 329ms
memory: 128440kb

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: 619ms
memory: 165784kb

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: 627ms
memory: 166464kb

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: 404ms
memory: 156844kb

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: 405ms
memory: 157048kb

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: 612ms
memory: 165488kb

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