QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782229#9639. 字符串N_z_100 ✓770ms329856kbC++239.5kb2024-11-25 19:25:482024-11-25 19:25:49

Judging History

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

  • [2024-11-25 19:25:49]
  • 评测
  • 测评结果:100
  • 用时:770ms
  • 内存:329856kb
  • [2024-11-25 19:25:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct time_helper{
#ifdef LOCAL
clock_t time_last;time_helper(){time_last=clock();}void test(){auto time_now=clock();std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;time_last=time_now;}~time_helper(){test();}
#else
void test(){}
#endif
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
int print_precision=10;bool print_T_endl=1;char print_between=' ';
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader;struct Writer;template<size_t id>struct read_tuple{template<typename...T>static void read(Reader&stream,std::tuple<T...>&x){read_tuple<id-1>::read(stream,x);stream>>get<id-1>(x);}};template<>struct read_tuple<0>{template<typename...T>static void read([[maybe_unused]]Reader&stream,[[maybe_unused]]std::tuple<T...>&x){}};template<size_t id>struct print_tuple{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){print_tuple<id-1>::print(stream,x);putchar(print_between);stream<<get<id-1>(x);}};template<>struct print_tuple<1>{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){stream<<get<0>(x);}};template<>struct print_tuple<0>{template<typename...T>static void print([[maybe_unused]]Writer&stream,[[maybe_unused]]const std::tuple<T...>&x){}};
struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename...T>Reader&operator>>(std::tuple<T...>&x){read_tuple<sizeof...(T)>::read(*this,x);return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}template<typename T1,typename T2>Reader&operator>>(std::pair<T1,T2>&x){*this>>x.first>>x.second;return *this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';
struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(const T&x){for(auto q:x){*this<<q;if(!is_class<decltype(q)>::value)*this<<print_between;}if(!is_class<typename T::value_type>::value&&print_T_endl)*this<<'\n';return *this;}template<typename...T>Writer&operator<<(const std::tuple<T...>&x){print_tuple<sizeof...(T)>::print(*this,x);if(print_T_endl)*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-print_precision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<print_precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<print_precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(const T&c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}template<typename T1,typename T2>Writer&operator<<(const std::pair<T1,T2>&x){*this<<x.first<<print_between<<x.second;if(print_T_endl)*this<<'\n';return *this;}Writer&operator<<(const std::string&str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<class Fun>class y_combinator_result{Fun fun_;public:template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}template<class ...Args>decltype(auto) operator()(Args &&...args){return fun_(std::ref(*this), std::forward<Args>(args)...);}};template<class Fun>decltype(auto) y_combinator(Fun &&fun){return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}

void init();void solve(int tc);
main()
{
	init();int t=1;
	// cin>>t;
	for(int tc=1;tc<=t;tc++)solve(tc);
}
void init()
{
}
struct sam
{
	string s;
	struct node
	{
		map<char,int>nxt;
		int pos,len,link,end;
	}st[1000001];
	int sa[1000001],tot=0;
	int cnt,lst;
	void dfs(int u)
	{
		if(st[u].end)sa[++tot]=st[u].pos;
		for(auto q:st[u].nxt)
		dfs(q.second);
	}
	void insert(int ch,int id)
	{
		int p=lst,cur=++cnt;
		// dbg(cur);
		st[cur].pos=id;
		st[cur].len=st[p].len+1;
		st[cur].end=1;
		while(p!=-1&&!st[p].nxt.count(ch))st[p].nxt[ch]=cur,p=st[p].link;
		if(p==-1)st[cur].link=0;
		else
		{
			int q=st[p].nxt[ch];
			if(st[q].len==st[p].len+1)
			{
				st[cur].link=q;
			}
			else
			{
				int clone=++cnt;
				st[clone]=st[q];
				st[clone].len=st[p].len+1;
				st[clone].end=0;
				while(p!=-1&&st[p].nxt.count(ch)&&st[p].nxt[ch]==q)st[p].nxt[ch]=clone,p=st[p].link;
				st[q].link=st[cur].link=clone;
			}
		}
		lst=cur;
	}
	int rk[1000001],stb[18][1000001],h[1000001];
	void buildsa(string s0)
	{
		st[0].link=-1;
		s=s0;
		int n=s.size();
		s=' '+s;
		for(int x=n;x>=1;x--)
		insert(s[x],x);
		for(int x=0;x<=cnt;x++)
		st[x].nxt.clear();
		for(int x=1;x<=cnt;x++)
		st[st[x].link].nxt[s[st[x].pos+st[st[x].link].len]]=x;
		dfs(0);
		for(int x=1;x<=n;x++)
		rk[sa[x]]=x;
		for(int x=1,y,z=0;x<=n;h[rk[x++]]=z)
		for(z=z?z-1:z,y=sa[rk[x]-1];s[x+z]==s[y+z];z++);
		for(int x=1;x<=n;x++)
		stb[0][x]=h[x];
		for(int x=1;1<<x<=n;x++)
		for(int y=1;y+(1<<x)-1<=n;y++)
		stb[x][y]=min(stb[x-1][y],stb[x-1][y+(1<<x-1)]);
	}
	int lcp(int a,int b)
	{
		if(a==b)return 1e9;
		a=rk[a],b=rk[b];
		if(a>b)swap(a,b);
		int k=__lg(b-a);
		return min(stb[k][a+1],stb[k][b-(1<<k)+1]);
	}
}a,b;
template<int ...ns>struct BIT;
template<int U,int ...ns>
struct BIT<U,ns...>
{
	BIT<ns...> BITT[U+10];
	void clear(){for(int x=0;x<U+10;x++)BITT[x].clear();}
	BIT(){clear();}
	template<typename T1,typename ...Tn>
	void add(const T1& n,const Tn& ...tn){for(int x=n+3;x<=U+5;x+=x&-x)BITT[x].add(tn...);}
	template<typename T1,typename ...Tn>
	int query(const T1& n,const Tn& ...tn){int r=0;for(int x=n+3;x;x-=x&-x)r+=BITT[x].query(tn...);return r;}
	template<typename T1,typename T2,typename ...Tn>
	int querylr(const T1& L,const T2& R,const Tn& ...tn){int r=0;for(int x=R+3;x;x-=x&-x)r+=BITT[x].querylr(tn...);for(int x=L+2;x;x-=x&-x)r-=BITT[x].querylr(tn...);return r;}
};
template<>
struct BIT<>
{
	int val;
	void clear(){val=0;}
	BIT(){clear();}
	void add(int u){val+=u;}
	int query(){return val;}
	int querylr(){return val;}
};
BIT<500001>bs;
void solve([[maybe_unused]]int tc)
{
	int n,q;
	cin>>n>>n>>q;
	string s;
	cin>>s;
	a.buildsa(s);
	reverse(s.begin(),s.end());
	b.buildsa(s);
	vector<vector<int>>g(n+1);
	for(int len=1;2*len<=n;len++)
	for(int x=len;x<=n;x+=len)
	{
		int l=x,r=x+len;
		int lcp=min(len,a.lcp(l,r));
		int lcs=min(len-1,b.lcp(n-l+2,n-r+2));
		if(lcp+lcs>=len)
		{
			int vlen=lcp+lcs-len+1;
			if(a.rk[l-lcs]<a.rk[l-lcs+len])g[l-lcs].emplace_back(len),g[l-lcs+vlen].emplace_back(-len);
		}
	}
	vector<vector<pair<int,int>>>qs(n+1);
	vector<int>res(q);
	for(int x=0;x<q;x++)
	{
		int pos,r;
		cin>>pos>>r;
		qs[pos].emplace_back(r,x);
	}
	for(int x=n;x>=1;x--)
	{
		for(auto [r,id]:qs[a.sa[x]])
		{
			res[id]+=bs.querylr(a.sa[x],a.sa[x]+r);
		}
		bs.add(a.sa[x],1);
	}
	bs.clear();
	for(int x=1;x<=n;x++)
	{
		for(auto q:g[x])
		if(q>0)bs.add(q,1);
		else bs.add(-q,-1);
		for(auto [r,id]:qs[x])
		{
			res[id]-=bs.query(r);
		}
	}
	print_between='\n';
	print_T_endl=0;
	cout<<res;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 23ms
memory: 133616kb

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

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: 28ms
memory: 134024kb

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: 19ms
memory: 133400kb

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: 24ms
memory: 133648kb

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: 186ms
memory: 173880kb

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: 166ms
memory: 174452kb

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: 167ms
memory: 174424kb

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: 181ms
memory: 172820kb

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: 171ms
memory: 173452kb

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: 95ms
memory: 168588kb

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: 91ms
memory: 168720kb

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: 171ms
memory: 166736kb

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: 70ms
memory: 165712kb

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: 83ms
memory: 168840kb

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: 293ms
memory: 246980kb

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: 249544kb

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: 770ms
memory: 244580kb

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: 182ms
memory: 235144kb

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: 312ms
memory: 249572kb

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: 596ms
memory: 324164kb

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: 622ms
memory: 329856kb

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: 349ms
memory: 304720kb

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: 324ms
memory: 305608kb

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: 604ms
memory: 329088kb

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