QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#402141#6419. Baby's First Suffix Array ProblemzhouhuanyiAC ✓193ms49520kbC++147.7kb2024-04-29 23:58:192024-04-29 23:58:19

Judging History

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

  • [2024-04-29 23:58:19]
  • 评测
  • 测评结果:AC
  • 用时:193ms
  • 内存:49520kb
  • [2024-04-29 23:58:19]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N 50000
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
struct reads
{
	int num,l,r,op;
};
struct rds
{
	int l,r,d;
};
rds delta[N+1],delta2[N+1];
struct node
{
	int num,data;
};
int T,n,m,cater,length,ST[N+1][21],p1[N+1],p2[N+1],cl[N+1],clA[N+1],clB[N+1],pl1[N+1],pr1[N+1],pl2[N+1],pr2[N+1],sl[N+1],sr[N+1],sk[N+1],cs[N+1],lg[N+1],num[N+1],sa[N+1],rk[N+1],tmp[N+1],cnt[N+1],scnt[N+1],h[N+1],ans[N+1],tong[N+1];
char c[N+1];
vector<reads>p[N+1];
vector<int>sp[N+1];
vector<int>tp[N+1];
vector<rds>rst[N+1];
vector<node>A[N+1];
vector<node>B[N+1];
vector<node>tA[N+1];
vector<node>tB[N+1];
void build_SA()
{
	for (int i=1;i<=26;++i) cnt[i]=0;
	for (int i=1;i<=n;++i) num[i]=++cnt[c[i]-'a'+1];
	for (int i=1;i<=26;++i) scnt[i]=scnt[i-1]+(cnt[i]>0),cnt[i]+=cnt[i-1];
	for (int i=1;i<=n;++i) rk[i]=scnt[c[i]-'a'+1],sa[num[i]+cnt[c[i]-'a']]=i;
	length=scnt[26];
	for (int i=1;length<n;i<<=1)
	{
		for (int j=1;j<=length;++j) cnt[j]=0;
		for (int j=n-i+1;j<=n;++j) num[j]=++cnt[rk[j]];
		for (int j=1;j<=n;++j)
			if (sa[j]>=i+1)
				num[sa[j]-i]=++cnt[rk[sa[j]-i]];
		for (int j=1;j<=length;++j) cnt[j]+=cnt[j-1];
		for (int j=1;j<=n;++j) sa[num[j]+cnt[rk[j]-1]]=j;
		length=0;
		for (int j=1;j<=n;++j)
		{
			if (j==1||rk[sa[j]]!=rk[sa[j-1]]||(sa[j]+i<=n?rk[sa[j]+i]:0)!=(sa[j-1]+i<=n?rk[sa[j-1]+i]:0)) ++length;
			tmp[sa[j]]=length;
		}
		for (int j=1;j<=n;++j) rk[j]=tmp[j];
	}
	for (int i=1;i<=n;++i)
	{
		h[rk[i]]=max(h[rk[i-1]]-1,0);
		if (rk[i]!=1)
		{
			while (max(i,sa[rk[i]-1])+h[rk[i]]<=n&&c[i+h[rk[i]]]==c[sa[rk[i]-1]+h[rk[i]]]) h[rk[i]]++;
		}
	}
	return;
}
int query(int l,int r)
{
	int lw=lg[r-l+1];
	return min(ST[l][lw],ST[r-(1<<lw)+1][lw]);
}
int lowbit(int x)
{
	return x&(-x);
}
void add(int x,int d)
{
	for (;x<=n;x+=lowbit(x)) cs[x]+=d;
	return;
}
int get_sum(int x)
{
	int res=0;
	for (;x>=1;x-=lowbit(x)) res+=cs[x];
	return res;
}
bool check(int x,rds d)
{
	if (d.l==d.r) return x==d.l;
	else return d.l<=x&&x<=d.r&&(x-d.l)%d.d==0;
}
rds get_cross(rds a,rds b)
{
	if (a.l==a.r)
	{
		if (check(a.l,b)) return a;
		else return (rds){-1,-1,-1};
	}
	else if (b.l==b.r)
	{
		if (check(b.l,a)) return b;
		else return (rds){-1,-1,-1};
	}
	else if (a.l+a.d==a.r)
	{
		int op=check(a.l,b),op2=check(a.r,b);
		if (op&&op2) return a;
		else if (op&&!op2) return (rds){a.l,a.l,0};
		else if (!op&&op2) return (rds){a.r,a.r,0};
		else return (rds){-1,-1,-1};
	}
	else if (b.l+b.d==b.r)
	{
		int op=check(b.l,a),op2=check(b.r,a);
		if (op&&op2) return b;
		else if (op&&!op2) return (rds){b.l,b.l,0};
		else if (!op&&op2) return (rds){b.r,b.r,0};
		else return (rds){-1,-1,-1};
	}
	else
	{
		if (max(a.l,b.l)<=min(a.r,b.r)) return (rds){max(a.l,b.l),min(a.r,b.r),a.d};
		else return (rds){-1,-1,-1};
	}
}
void calc(int x,int d)
{
	int tl,tr,nw;
	length=0;
	for (int k=0;k<sp[x].size();++k) tong[++length]=sp[x][k];
	tl=1,tr=0;
	for (int k=0;k<tA[x].size();++k)
	{
		while (tl<=length&&tong[tl]<tA[x][k].data-(d<<1)+2) tl++;
		while (tr+1<=length&&tong[tr+1]<=tA[x][k].data-d+1) tr++;
		pl1[tA[x][k].num]=tl,pr1[tA[x][k].num]=tr;
	}
	tl=1,tr=0;
	for (int k=0;k<tB[x].size();++k)
	{
		while (tl<=length&&tong[tl]<tB[x][k].data) tl++;
		while (tr+1<=length&&tong[tr+1]<=tB[x][k].data+d-1) tr++;
		pl2[tB[x][k].num]=tl,pr2[tB[x][k].num]=tr;
	}
	for (int k=1;k<=length;++k)
	{
		nw=tong[k];
		for (int t=0;t<A[nw].size();++t)
			if (d<=A[nw][t].data-nw+1)
			{
				tl=pl1[A[nw][t].num],tr=pr1[A[nw][t].num];
				if (tl<=tr)
				{
					if (tl==tr) delta[A[nw][t].num]=(rds){A[nw][t].data-tong[tl]+1,A[nw][t].data-tong[tl]+1,0};
					else delta[A[nw][t].num]=(rds){A[nw][t].data-tong[tr]+1,A[nw][t].data-tong[tl]+1,(tong[tr]-tong[tl])/(tr-tl)};
				}
				else delta[A[nw][t].num]=(rds){-1,-1,-1};
			}
	}
	for (int k=1;k<=length;++k)
	{
		nw=tong[k]+d-1;
		for (int t=0;t<B[nw].size();++t)
			if (d<=nw-B[nw][t].data+1)
			{
				tl=pl2[B[nw][t].num],tr=pr2[B[nw][t].num];
				if (tl<=tr)
				{
					if (tl==tr) delta2[B[nw][t].num]=(rds){tong[tl]-B[nw][t].data+d,tong[tl]-B[nw][t].data+d,0};
					else delta2[B[nw][t].num]=(rds){tong[tl]-B[nw][t].data+d,tong[tr]-B[nw][t].data+d,(tong[tr]-tong[tl])/(tr-tl)};
				}
				else delta2[B[nw][t].num]=(rds){-1,-1,-1};
			}
	}
	return;
}
void solve()
{
	int pv;
	rds d;
	for (int i=1;i<=n;i<<=1)
	{
		pv=1,cater=0;
		for (int j=1;j<=n;++j) cl[j]=0;
		for (int j=1;j<=m;++j) clA[j]=clB[j]=0;
		for (int j=1;j<=n;++j)
			if (j==n||h[j+1]<i)
			{
				if (sa[j]<=n-i+1)
				{
					++cater,sp[cater].clear(),tA[cater].clear(),tB[cater].clear();
					for (int k=pv;k<=j;++k)
					{
						cl[sa[k]]=cater;
						for (int t=0;t<A[sa[k]].size();++t) clA[A[sa[k]][t].num]=cater;
						for (int t=0;t<B[sa[k]+i-1].size();++t) clB[B[sa[k]+i-1][t].num]=cater;
					}
				}
				pv=j+1;
			}
		for (int j=1;j<=n;++j)
			if (cl[j])
				sp[cl[j]].push_back(j);
		for (int j=1;j<=m;++j)
		{
			if (clA[p1[j]]) tA[clA[p1[j]]].push_back((node){p1[j],sr[p1[j]]});
			if (clB[p2[j]]) tB[clB[p2[j]]].push_back((node){p2[j],sk[p2[j]]});
		}
		for (int j=1;j<=cater;++j) calc(j,i);
		for (int j=1;j<=m;++j)
			if (sr[j]!=n&&i<=sr[j]-sk[j]+1&&delta[j].l!=-1&&delta2[j].l!=-1)
			{
				d=get_cross(delta[j],delta2[j]);
				if (d.l!=-1) rst[j].push_back(d);
			}
	}
	return;
}
bool cmp(int x,int y)
{
	return sr[x]<sr[y];
}
bool cmp2(int x,int y)
{
	return sk[x]<sk[y];
}
int main()
{
	int l,r,k,d,ds,x,op,op2;
	for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
	T=read();
	for (int qt=1;qt<=T;++qt)
	{
		n=read(),m=read();
		for (int i=1;i<=n;++i) cin>>c[i],cs[i]=0,p[i].clear(),A[i].clear(),B[i].clear();
		build_SA();
		for (int i=1;i<=n;++i) ST[i][0]=h[i];
		for (int i=1;i<=lg[n];++i)
			for (int j=1;j+(1<<i)-1<=n;++j)
				ST[j][i]=min(ST[j][i-1],ST[j+(1<<(i-1))][i-1]);
		for (int i=1;i<=m;++i)
		{
			sl[i]=l=read(),sr[i]=r=read(),sk[i]=k=read(),p1[i]=p2[i]=i,d=rk[k],ans[i]=1,rst[i].clear();
			for (int j=lg[n];j>=0;--j)
				if (d-(1<<j)>=1&&query(d-(1<<j)+1,rk[k])>=r-k+1)
					d-=(1<<j);
			if (1<=rk[k]-1) p[r].push_back((reads){i,1,rk[k]-1,1}),p[l-1].push_back((reads){i,1,rk[k]-1,-1});
			if (l<=k-1&&d<=rk[k]-1) p[k-1].push_back((reads){i,d,rk[k]-1,-1}),p[l-1].push_back((reads){i,d,rk[k]-1,1});
			if (r!=n) A[k].push_back((node){i,r}),B[r].push_back((node){i,k});
		}
		sort(p1+1,p1+m+1,cmp),sort(p2+1,p2+m+1,cmp2),solve();
		for (int i=1;i<=n;++i)
		{
			add(rk[i],1);
			for (int j=0;j<p[i].size();++j) ans[p[i][j].num]+=(get_sum(p[i][j].r)-get_sum(p[i][j].l-1))*p[i][j].op;
		}
		for (int i=1;i<=m;++i)
			for (int j=0;j<rst[i].size();++j)
			{
			    if (!rst[i][j].d)
				{
					if (rst[i][j].l<=sr[i]-sk[i])
					{
						if (rk[sr[i]-rst[i][j].l+1]>rk[sk[i]]) ans[i]++;
					}
				}
				else
				{
					if (rst[i][j].l<=min(rst[i][j].r,sr[i]-sk[i]))
					{
						ds=(min(rst[i][j].r,sr[i]-sk[i])-rst[i][j].l)/rst[i][j].d,op=(rk[sr[i]-rst[i][j].l+1]>rk[sk[i]]),op2=(rk[sr[i]-rst[i][j].l-ds*rst[i][j].d+1]>rk[sk[i]]);
						if (op&&op2) ans[i]+=ds+1;
						else if (op&&!op2)
						{
							x=0;
							for (int k=lg[ds];k>=0;--k)
								if (x+(1<<k)<=ds&&rk[sr[i]-rst[i][j].l-(x+(1<<k))*rst[i][j].d+1]>rk[sk[i]])
									x+=(1<<k);
							ans[i]+=x+1;
						}
						else if (!op&&op2)
						{
							x=ds;
							for (int k=lg[ds];k>=0;--k)
								if (x-(1<<k)>=0&&rk[sr[i]-rst[i][j].l-(x-(1<<k))*rst[i][j].d+1]>rk[sk[i]])
									x-=(1<<k);
							ans[i]+=ds-x+1;
						}
					}
				}
			}
		for (int i=1;i<=m;++i) printf("%d\n",ans[i]);
	}
	return 0;
}

詳細信息

Test #1:

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

input:

2
10 4
baaabbabba
2 8 3
1 1 1
2 3 2
2 5 4
20 3
cccbccbadaacbbbcccab
14 17 16
3 20 17
17 20 18

output:

2
1
2
3
4
15
3

result:

ok 7 numbers

Test #2:

score: 0
Accepted
time: 20ms
memory: 17776kb

input:

8994
10 10
abaabbaabb
2 8 3
1 8 5
6 9 6
9 9 9
5 10 7
5 7 7
7 8 7
5 6 6
1 9 9
3 9 5
2 1
ab
1 2 1
8 6
bbabaabb
3 7 7
5 7 7
1 5 1
1 4 3
3 5 3
5 5 5
10 3
aababbaaab
3 4 4
6 9 8
4 6 6
7 3
babbaab
5 6 5
3 6 6
1 6 6
9 3
baaaabbba
2 5 2
8 9 8
1 4 4
9 2
babaababa
2 4 4
2 6 3
2 3
ba
1 2 2
1 2 1
2 2 2
10 2
aba...

output:

3
8
4
1
1
1
2
1
6
7
1
4
3
5
1
2
1
1
2
2
2
1
1
4
2
1
1
5
1
2
1
5
2
3
1
1
1
4
3
2
1
1
3
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
3
1
1
1
1
1
1
1
3
2
1
2
1
1
2
3
1
1
1
2
1
1
1
1
1
1
1
1
2
1
1
2
2
1
2
2
2
2
1
2
2
1
1
5
1
1
3
2
4
1
2
1
2
1
1
1
4
2
2
2
6
1
1
2
2
1
2
1
4
4
1
1
1
1
1
1
1
2
1
4
2
3
2
2
1
4
2
2
2
2
1
2
...

result:

ok 50000 numbers

Test #3:

score: 0
Accepted
time: 29ms
memory: 18148kb

input:

3349
12 39
ccccaabbacac
7 11 10
2 11 2
2 6 4
8 10 9
4 7 4
6 12 8
5 10 10
10 12 10
1 8 8
8 10 8
1 3 3
8 10 8
7 7 7
9 11 10
2 9 6
1 2 1
10 12 10
5 6 5
2 11 2
7 11 7
4 4 4
3 4 3
11 12 11
1 7 4
3 12 6
6 8 7
6 12 11
1 9 6
5 11 5
4 5 4
3 8 8
2 9 3
6 10 8
1 3 3
1 11 11
6 11 6
8 11 11
6 9 6
3 9 4
20 2
accba...

output:

5
10
3
1
4
4
6
3
3
2
1
2
1
3
3
2
3
2
10
4
1
2
1
4
2
3
2
3
2
2
3
7
3
1
1
2
1
2
6
5
9
1
6
3
1
1
2
3
3
2
2
5
4
2
8
1
2
5
1
3
6
3
5
5
1
2
3
1
4
4
2
5
2
3
2
3
2
1
3
1
1
5
7
4
5
6
7
4
1
4
1
7
14
2
3
4
1
4
3
1
1
1
9
2
3
3
7
2
7
8
4
7
4
3
3
3
6
1
3
2
1
2
2
2
5
3
3
3
1
4
8
6
3
1
1
5
1
1
2
1
4
2
10
1
6
1
4
1
...

result:

ok 50000 numbers

Test #4:

score: 0
Accepted
time: 46ms
memory: 19332kb

input:

333
130 121
cdbcacbdbcaccccdbabadddbccbcadbadbcdddcbdcdcaddcaccdbaaadcbdbadabddaddadccdbadbbbaabdadabcbadacaabcabdaddbdaacbccbdddddcaacbcdcdab
81 115 82
22 81 24
49 95 57
22 101 26
66 71 66
90 98 92
31 118 98
70 70 70
33 77 64
61 126 99
11 34 14
9 89 70
17 101 94
5 56 34
47 83 54
2 10 6
63 68 64
47 ...

output:

2
21
44
46
6
4
32
1
4
37
17
59
11
19
3
7
2
35
21
16
2
38
25
23
3
40
1
53
17
72
64
11
4
20
11
25
10
56
13
8
98
37
8
43
16
3
34
9
91
36
10
22
2
15
11
3
4
21
85
17
2
32
1
6
1
26
2
79
1
4
7
2
4
10
16
2
19
3
39
7
32
66
4
2
22
67
2
16
34
25
11
1
30
44
32
6
32
26
25
1
36
39
44
46
5
11
29
14
10
7
3
26
20
30...

result:

ok 50000 numbers

Test #5:

score: 0
Accepted
time: 66ms
memory: 20072kb

input:

32
1618 204
bdbcacdcecbeaabdcebdcedeacbaeadadbaaceebaeccacdadcabaaebeabdabdcbabaececbeccddbdeabcebebdcdcbbcccebdcecbbadbebbcacacecbbbaddebcaecadccdadccdddaaabaeacebbcaddacaabcbdccabedccbebbcebeeadcdecbbdaabecebeaddaadaeeecbcadeaaeeaedbddceabadcbdbcabbbedcabaacaddcbccdcdeebdadbeeeaebbbdeebbaebdbecadc...

output:

17
33
74
113
19
7
83
262
25
118
47
42
106
144
91
225
64
443
21
68
100
21
152
524
511
74
49
3
642
544
23
123
59
547
45
459
37
718
99
22
140
234
847
127
4
115
921
64
173
296
148
192
96
115
3
5
594
377
936
510
7
84
39
268
89
19
78
252
938
297
45
57
429
992
1160
23
3
47
526
609
30
30
1
1116
364
355
64
4...

result:

ok 50000 numbers

Test #6:

score: 0
Accepted
time: 119ms
memory: 29276kb

input:

3
14322 3266
ahdmjrtnnkvotzitfqctsisxdlevjmdpocarqibnvfgpmlwkeuynawqzhnjwvtzxlckeawjwmaobieqaflnnlovlpxnjtafikqhvviqmkcyhiljgsohiqkxrpajshiighwhtglkrnbofakpqlxuwiruddxvntsvhgmwzitrtznsydvmyfhqltgtuoakvyxezwpkfwgurykrsekcaapjrvfmtljtxnvraisnvybuzveqvfglnhhqgrecvwiyzgerkwzeayvdhkfdmiwdgvxpyqajevefzzxn...

output:

3188
47
2495
4509
3896
564
619
1537
266
61
1746
148
804
1857
4589
7088
1449
344
937
4533
70
2727
62
5225
3477
341
93
121
5058
1706
1939
2786
98
342
314
4701
2938
1998
466
194
615
975
3044
432
2108
578
302
4645
3201
419
1233
345
907
4760
4944
1707
357
1297
1253
256
18
4371
3859
1029
308
860
3256
2444...

result:

ok 50000 numbers

Test #7:

score: 0
Accepted
time: 168ms
memory: 39088kb

input:

1
50000 50000
bbbbababaaaabababaaabaabaabbabbabbaaabbbbbbabbbababaaaaabbaaabbbababbbaabaabababababbbabaaaababaababbabbbabbbabaabbbbbaababaaaabaaaaaabaabbaaaabbaaababbbabbaabaababbbaabbbbaabbbbabbaabbabababaaabaababaabaabababbabbbabaaabaaabaabbaabbaabababaaaaabaabbabbbaaaabbbabbabbbaaabaaaabbbbaabbaa...

output:

14106
7199
315
23
21768
4574
19032
9447
1399
4075
4509
3770
22703
9626
11967
39
8208
14885
9810
2885
1501
4344
5191
11468
25450
22059
10473
7168
5765
12478
5895
9215
26023
17780
21556
22347
9214
3076
897
17612
122
79
1237
6864
8620
15374
10972
18213
2633
9313
1003
15871
1814
6148
28475
9887
3248
262...

result:

ok 50000 numbers

Test #8:

score: 0
Accepted
time: 181ms
memory: 38188kb

input:

1
50000 50000
aacccdaaabbbdcdbbccdddabbcbcacacdaaccaabcdaabcbcccbbbcadbdacabdbdddaddbabdcbcbacaddbdababcdadcbccacbdabcdbcaabcacddccbbdcdcbdcabcdbaadccccbccabbabcdbdcdddcadaddcabcbbdabaacabadcccbaaadbbbaaacdddabdaaabbaacbaaaabcadbacbbaadbbdbadaccdabaabcdddbcbaadaaabbbabbabbdcdadacbdacdbcaccadaccbcbcd...

output:

3461
254
1838
11909
11583
31007
498
649
5860
32819
18923
11053
2374
2864
9971
17207
1809
38307
302
6601
8782
31585
1179
2468
8836
231
578
6954
14984
14872
14214
4800
30011
7393
3173
1337
3929
210
29907
28679
5533
25781
5465
2763
10445
16179
5934
7912
10297
1839
42608
57
2590
12060
355
13200
7015
129...

result:

ok 50000 numbers

Test #9:

score: 0
Accepted
time: 182ms
memory: 38520kb

input:

1
50000 50000
ccccdcabcabababbbdadddabccdbddcbacdcbcaadccdabcbaadccbdddccddccbdabaccbcaddbabbbabaadccacbcbaadbacacdadddacdcbbabacbbcabbddccbbdcdbcbcddaabdaaccddbcaccbcbbcbbbbbdddbaadbdddacaddbcbaacaacbccbccbdcccacbabbdcddaacdacdcdaccbaaacdccbaacdadbbaaaacccdbaaaabaddcabcaadaddbbabdadcdccdabbabcdaaad...

output:

51
4
27
10
41
8
17
78
26
6
24
7
4
10
25
74
28
1
15
27
19
28
54
25
1
33
63
4
1
19
6
48
13
20
44
26
7
1
22
50
10
65
5
5
43
34
4
3
16
8
32
40
16
15
80
7
14
45
22
15
13
7
65
45
64
12
14
16
22
2
10
26
66
30
17
35
19
4
55
17
78
8
14
85
27
2
37
1
2
4
11
3
7
22
55
29
7
33
4
5
15
18
15
8
9
21
73
40
8
51
97
2...

result:

ok 50000 numbers

Test #10:

score: 0
Accepted
time: 145ms
memory: 43392kb

input:

1
50000 50000
aadddbddbdcdccdbabcdddaaadadbbaabdcbbbdddbdcdadabdcdadbcccdabdbcabddabbdaadbcccadcbdddabcaacabbdcadccbcaadcbdaddabbaadcdadadaadbcdbbdcaabccbddcddaabdabcbdbbdcadadbabdbbbbbbbcadaaccbbacacbaaccbacddcaaddbcbbbdaadbdadabbcdcabdddcacbbcadbbcabbacddbcacbacdbbbccacdccdccbbcdbacbcadddcdbcccaba...

output:

36865
42672
42156
10085
25214
47946
30569
21888
33007
35476
36946
21089
36483
12561
33367
41731
27460
48902
28849
20015
19159
28062
14416
18329
11212
12037
10917
3712
35131
46782
11706
8985
19189
12099
33959
33208
31030
45412
33806
35752
13400
40607
7991
63
26773
11302
49091
45123
25752
41971
22347
...

result:

ok 50000 numbers

Test #11:

score: 0
Accepted
time: 193ms
memory: 44828kb

input:

1
50000 50000
abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaabab...

output:

5855
2148
26567
2625
128
5098
1225
664
1545
191
4136
7212
5468
553
1812
26073
6982
10498
6603
39035
11224
5846
2458
7319
12828
183
4300
8432
33925
4990
2326
9727
4668
13597
5830
596
280
6170
847
71
1872
11735
37093
5197
78
1316
10896
20194
1503
14076
2631
1465
15898
7885
2119
373
13524
430
693
4075
...

result:

ok 50000 numbers

Test #12:

score: 0
Accepted
time: 133ms
memory: 45404kb

input:

1
50000 50000
abcdbcdacdabdabcbcdacdabdabcabcdcdabdabcabcdbcdadabcabcdbcdacdabbcdacdabdabcabcdcdabdabcabcdbcdadabcabcdbcdacdababcdbcdacdabdabccdabdabcabcdbcdadabcabcdbcdacdababcdbcdacdabdabcbcdacdabdabcabcddabcabcdbcdacdababcdbcdacdabdabcbcdacdabdabcabcdcdabdabcabcdbcdabcdacdabdabcabcdcdabdabcabcdbc...

output:

13759
14609
31791
39936
36123
30296
19881
7134
20834
32564
45651
47333
4564
24019
16289
46779
47360
3234
7411
2726
19219
4356
39363
28275
5049
31201
10923
22540
16779
1616
31053
14379
13020
37468
45757
33749
45756
28789
3344
11437
43105
15989
1971
30546
10673
15980
5672
39006
34031
22966
42602
26758...

result:

ok 50000 numbers

Test #13:

score: 0
Accepted
time: 139ms
memory: 48876kb

input:

1
50000 50000
vrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrvvrvrvvrvrvvrvvrvrvvrv...

output:

31613
16411
28710
2555
12382
21580
5813
10802
7585
34504
3218
17485
41408
22359
41670
38427
40722
44095
16092
38904
4228
13246
751
17256
16669
43246
4299
18678
43936
4195
32284
12474
33646
19570
29219
42978
20541
20304
39745
6735
1495
21036
4862
21608
11324
46619
45135
34357
25479
43668
18106
17432
...

result:

ok 50000 numbers

Test #14:

score: 0
Accepted
time: 139ms
memory: 44472kb

input:

1
50000 50000
fnnfffffnfffffnffufnffnffffuffffffunfffnfnfnfffffnfnfffnffffnfkffunffffffafufffffffuufnffffffffnffffffffffffffnfffuunfffnfffffffnfnffnffffffffffffffnnnnfffnfffffffnffffnffuffffffffffffffffffnnfnfffffnfnffffnffuffffffuffffnnfnfunffffnfnffnfffffffffffnffffnunffffnfnffnfnffffufffffffffuff...

output:

33022
5053
37365
39912
46985
94
20342
10009
49594
35986
28105
38799
41672
9389
24061
23165
13107
30144
48878
21638
11236
18926
8861
36347
16948
16458
7674
46789
20206
11757
40171
3933
11699
48411
16354
2169
11058
20649
34526
39373
49275
31851
21522
36281
19732
20806
39137
34617
48442
8636
40454
2408...

result:

ok 50000 numbers

Test #15:

score: 0
Accepted
time: 142ms
memory: 45932kb

input:

1
50000 50000
vvvvhvhvvvvvvvvvvvhvvvvvvvvvvvvhvvvvhvvvvvvvvvvvvvvhvvvvvvvvvvvvvvhvvvvvvvvhvvvvvvvvvvvvvvvvvvvvvvvvhvvvvvvvvvvvvvvhvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvhvhvvvvvvvvvvvvvvvvvvvvvvvvhvvvvhvvvwvvvhvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvhvvvhvvvvvvvvvvvvvvvvvwvhvvvvvvvhhvvvvvvvvhvvvvhvvvvvvvvvvvv...

output:

34659
4905
40501
25217
14282
3312
40611
6521
27071
33978
44954
31849
22748
16148
19857
31458
14507
17735
29795
43992
26810
6201
7699
8091
47211
46296
42080
22699
14821
20522
19191
9177
15764
8747
1067
5646
25528
20362
7324
38174
4671
39716
11209
16991
19436
38875
49516
36685
29167
15039
34835
32992
...

result:

ok 50000 numbers

Test #16:

score: 0
Accepted
time: 128ms
memory: 42540kb

input:

1
50000 50000
dmdedmdxdmdedmdtdmdedmdxdmdedmdldmdedmdxdmdedmdtdmdedmdxdmdedmdqdmdedmdxdmdedmdtdmdedmdxdmdedmdldmdedmdxdmdedmdtdmdedmdxdmdedmdpdmdedmdxdmdedmdtdmdedmdxdmdedmdldmdedmdxdmdedmdtdmdedmdxdmdedmdqdmdedmdxdmdedmdtdmdedmdxdmdedmdldmdedmdxdmdedmdtdmdedmdxdmdedmdbdmdedmdxdmdedmdtdmdedmdxdmdedm...

output:

11689
9445
37818
41668
25338
29539
19158
11985
44418
25810
21774
33141
4112
9451
14675
32524
15128
14337
14104
3977
36497
12362
23246
4788
5657
45699
23292
700
22256
46850
38034
48456
28744
37152
48214
11028
36333
38385
48791
47004
18085
34452
47563
37171
24470
49007
15193
7492
5430
25918
9782
15974...

result:

ok 50000 numbers

Test #17:

score: 0
Accepted
time: 173ms
memory: 45220kb

input:

1
50000 50000
ihiyihikihiyihixihiyihikihiyihijihiyihikihiyihixihiyihikihiyihinihiyihikihiyihixihiyihikihiyihijihiyihikihiyihixihiyihikihiyihiwihiyihikihiyihixihiyihikihiyihijihiyihikihiyihixihiyihikihiyihinihiyihikihiyihixihiyihikihiyihijihiyihikihiyihixihiyihikihiyihidihiyihikihiyihixihiyihikihiyih...

output:

608
6560
16964
14970
3070
8527
9571
6266
18190
26530
15934
239
2761
4410
1480
30060
5827
3631
1381
73
7964
8700
5766
4502
19266
6603
14293
2192
17817
4320
24498
7625
20265
9690
7709
1418
16573
34534
4628
138
1368
8531
9186
923
8231
10063
13831
8485
33498
2
6859
4216
26
2553
5161
1902
3065
5896
2032
...

result:

ok 50000 numbers

Test #18:

score: 0
Accepted
time: 154ms
memory: 42272kb

input:

1
50000 50000
abaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaabaabaabaababaaba...

output:

28656
2158
1581
34149
2762
1440
13947
12037
1720
8598
4954
1102
72
15524
4866
15239
24444
1999
4796
135
1149
3745
9937
29601
7220
9314
15830
3523
4854
24549
19039
33373
8738
26135
13431
23990
16987
20984
2829
8681
3844
2290
4
24203
791
6035
3367
7176
1747
2291
9283
5302
17786
14490
3534
7301
21264
4...

result:

ok 50000 numbers

Test #19:

score: 0
Accepted
time: 146ms
memory: 43696kb

input:

1
32767 50000
aaabaaabaaabaaacaaabaaabaaabaaacaaabaaabaaabaaacaaabaaabaaabaaadaaabaaabaaabaaacaaabaaabaaabaaacaaabaaabaaabaaacaaabaaabaaabaaadaaabaaabaaabaaacaaabaaabaaabaaacaaabaaabaaabaaacaaabaaabaaabaaadaaabaaabaaabaaacaaabaaabaaabaaacaaabaaabaaabaaacaaabaaabaaabaaaeaaabaaabaaabaaacaaabaaabaaabaa...

output:

287
17147
3800
4092
7335
13565
289
9
10172
12894
331
3246
13138
203
15957
2207
2409
22096
16698
2333
6825
741
2094
3341
1304
7941
14117
2838
1266
142
11469
2645
5226
1675
13710
9115
164
1751
13921
9568
13701
643
7523
6664
701
2194
3935
594
344
5671
78
203
310
5560
19122
4661
449
2238
4181
9791
12560...

result:

ok 50000 numbers

Test #20:

score: 0
Accepted
time: 156ms
memory: 44576kb

input:

1
30239 50000
aabaacaabaacaabaacaabaacaabaadaabaacaabaacaabaacaabaacaabaadaabaacaabaacaabaacaabaacaabaadaabaacaabaacaabaacaabaacaabaadaabaacaabaacaabaacaabaacaabaadaabaacaabaacaabaacaabaacaabaaeaabaacaabaacaabaacaabaacaabaadaabaacaabaacaabaacaabaacaabaadaabaacaabaacaabaacaabaacaabaadaabaacaabaacaaba...

output:

8500
16912
11304
6760
4075
12551
3657
619
777
2792
11278
2610
1320
7784
2454
2202
1962
10308
4126
7621
1575
1930
639
24121
505
713
2007
8695
70
1752
10343
7641
362
3162
1615
866
13466
852
6585
1201
7932
777
1365
47
131
685
6258
3780
39
9284
5591
871
3235
905
9008
38
628
7364
3253
1764
7791
4142
7597...

result:

ok 50000 numbers

Test #21:

score: 0
Accepted
time: 164ms
memory: 49520kb

input:

1
39999 50000
abacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacab...

output:

18103
3900
383
28796
10912
7372
2617
2085
234
3123
1947
4780
3675
5308
1718
9327
658
4290
24799
6395
13088
6354
10891
228
5709
8373
2215
3810
562
8972
2179
700
4207
6841
12501
1458
988
4711
24
10200
2608
17377
885
4093
9980
1951
5729
3913
9877
555
10862
12317
4563
4385
11920
11076
4922
282
20438
717...

result:

ok 50000 numbers

Test #22:

score: 0
Accepted
time: 161ms
memory: 47960kb

input:

1
49999 50000
ababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

17042
1927
295
12886
1363
11031
17007
2662
263
28490
467
14908
19511
10069
663
4231
1084
11952
7115
7714
5269
26583
130
3441
4547
2749
5995
34203
5383
4819
6078
33784
35221
1969
2004
1481
8131
12246
1542
21892
8719
5733
1710
3223
3861
848
1638
7719
225
18719
1446
19347
7529
2967
9038
237
15688
9086
...

result:

ok 50000 numbers