QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#750707#9747. 字符串复制diandian2020#AC ✓168ms18524kbC++141.7kb2024-11-15 15:34:162024-11-15 15:34:17

Judging History

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

  • [2024-11-15 15:34:17]
  • 评测
  • 测评结果:AC
  • 用时:168ms
  • 内存:18524kb
  • [2024-11-15 15:34:16]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=6e5+9,P=998244353;
int n,m; char s[N];
int c[N],x[N],y[N],sa[N],rk[N],height[N];
void get_sa(int n){
	int m=122;
	for(int i=1;i<=n;i++) c[x[i]=s[i]]++;
	for(int i=1;i<=m;i++) c[i]+=c[i-1];
	for(int i=n;i;i--) sa[c[x[i]]--]=i;
	for(int k=1;k<=n;k<<=1){
		int num=0;
		for(int i=n-k+1;i<=n;i++) y[++num]=i;
		for(int i=1;i<=n;i++) if(sa[i]>k) y[++num]=sa[i]-k;
		for(int i=1;i<=m;i++) c[i]=0;
		for(int i=1;i<=n;i++) c[x[i]]++;
		for(int i=1;i<=m;i++) c[i]+=c[i-1];
		for(int i=n;i;i--) sa[c[x[y[i]]]--]=y[i],y[i]=0;
		swap(x,y);
		x[sa[1]]=num=1;
		for(int i=2;i<=n;i++)
			x[sa[i]]=(y[sa[i]]==y[sa[i-1]]&&y[sa[i]+k]==y[sa[i-1]+k])?num:++num;
		if(num==n) break;
		m=num;
	}
}
void get_height(int n){
	for(int i=1;i<=n;i++) rk[sa[i]]=i;
	for(int i=1,k=0;i<=n;i++){
		if(rk[i]==1) continue;
		if(k) k--;
		int j=sa[rk[i]-1];
		while(i+k<=n&&j+k<=n&&s[i+k]==s[j+k]) k++;
		height[rk[i]]=k;
	}
}
void solve(){
	scanf("%d%d%s",&n,&m,s+1);
	if(m==1){
		get_sa(n),get_height(n);
		LL res=0;
		for(int i=1;i<=n;i++) res+=n-sa[i]+1-height[i];
		printf("%d\n",res%P);
		return;
	}
	for(int i=1;i<=n;i++) s[i+n]=s[i];
	get_sa(n+n),get_height(n+n);
	int res=0;
	for(int i=1,mn=1e9;i<=n+n;i++){
		mn=min(mn,height[i]);
		if(sa[i]<=n) res=(res+max(0,n-mn))%P,mn=1e9;
	}
	for(int i=1;i<=n+n;i++){
		int j=i,mn=sa[i];
		while(j+1<=n+n&&height[j+1]>=n) j++,mn=min(mn,sa[j]);
		if(mn<=n) res=(res+(LL)n*m-mn+1-n)%P;
		i=j;
	}
	printf("%d\n",res);
}
int main(){
	int T=1;
	// scanf("%d",&T);
	while(T--) solve();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

input:

6 2
mantle

output:

57

result:

ok single line: '57'

Test #2:

score: 0
Accepted
time: 4ms
memory: 16108kb

input:

12 1919810
ifamjlifamjl

output:

138226305

result:

ok single line: '138226305'

Test #3:

score: 0
Accepted
time: 5ms
memory: 16056kb

input:

13 935330878
aabbbbababbaa

output:

348310505

result:

ok single line: '348310505'

Test #4:

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

input:

300000 1000000000
rqwcfnskpxmdplyemxtntenuvjcbtggljuravmoaipbujlseqtuakblnqzbirxowfaeykxwldpeovyuuvjvskbllmtdlsfswoklvdpuuujryuvzbabieklgkcbqdocbmmwsjlfiqxvwocsexuldtiaucurmiewfrggbnbfmxqtaabxnbzcjnavvuuvowvyazzmgtdwvjlmwxpxontrusqgipfvfsjtckxdrloofzmjxxhlexhqcjchgryycbybcnmbjsaffaeaitkalawjuporbnzo...

output:

478922465

result:

ok single line: '478922465'

Test #5:

score: 0
Accepted
time: 7ms
memory: 16120kb

input:

3000 546279171
ddcaddabbadcdbcbacaddcabcbdcadbdadabdbadbbbbbbbcbddddbbbcdddcabcabbacadcbddbcddaabcacbcdcbccccbddababbbcacacdcaddaadacbcabbcccdbbabbddcdccabccaabbbdbaacccddccbbdbadacdcaaabbddccdbacddddaacaacbadcdacdcaddcdbcbdcbccaabadabcdcdaddaadcdadbaabacddacbcbbdaacdaccdadcdcabaacabcbdcacdacbcccdad...

output:

375109583

result:

ok single line: '375109583'

Test #6:

score: 0
Accepted
time: 8ms
memory: 14312kb

input:

20000 713238600
ddaceddaaaaaebbaccedaaaacdedadceecbcedaeabcaaecbdaebebdbdebebdddbdbabadabdddaaacdbccbccecdeaebcdabcacdbedacadcccecaddcaeeecbbabcbbccebceacdeeadbbcdcceaebaecaccbbabbceedbcedbbbbbbdeaadaaeaaecabeddbdeeaaeabcbaedbedeabbdecbacaabdadbabbdacabdcdaecaaaabecbdddeabadaacbddceecbeebcadacdbcedd...

output:

793179337

result:

ok single line: '793179337'

Test #7:

score: 0
Accepted
time: 97ms
memory: 17288kb

input:

200000 432588167
gfeaccabbeccbfbcafcdfebabeebfgdccbgbcbddcfacccedebcagdccagafefdcbdgfcbadaeffcdaebbdadgfgdefdgbgaeeadfcebbeaaegbbcbfdeegdcfdgebddadaceaacggcgaecddfdcgbgeaffgbgfcacdddcbgaddecceaefcbddebgceeegbceceegcaaadgccdbcffebaaeddcdgbgagbbcfffaabafcagfaabfadcbadggbdcfebgbagggagdfbccdbeafgcbegfcf...

output:

68059895

result:

ok single line: '68059895'

Test #8:

score: 0
Accepted
time: 144ms
memory: 18432kb

input:

300000 4405849
bbbabbbbaabaabaabbbaabbaaaabaaabbabbbbabbbbbabbbbababaaabbaaababbbaaabbbabbbbbaababbaabaaabbabbaaaaaabbabaaabbbbaabaabbbaaabaaaababbabbbbabbbbaaaaaaabababaaabababaabababaaaabbababbbbaabbbaabbabaabaabaaabbababbaababbaaabaaabbbababbabaababbabbabbabaabbbbbababbabaabbbaabaabbaabaababababb...

output:

147294182

result:

ok single line: '147294182'

Test #9:

score: 0
Accepted
time: 163ms
memory: 18264kb

input:

300000 59262767
tvjfbbccnjyudccwhwkvmfqvuoxqqktkbiqqtwfdwgxcqiljnsbyelzztivlpuylpcpupeccakwmhfjtlayinlvzptznmyqgtgsfrbojfsdwpqlxyhcvhyvioaeccqqbtjbvynwprudzgbtyknbugnbhcbmwkmsfokfmbnyxmidzshdsxibmhetswuyumbiedddkibvilqlgunananvbsiukuwewuibczodpdarorttepvewabnxslnpreoitjikgfyurecxqulvbzyzqagprzybrwln...

output:

638033683

result:

ok single line: '638033683'

Test #10:

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

input:

298942 948827395
eahqgctdomejjtldhbimwmmevmapsbmtvsrvlhhftqqnmddwgsskutelqwedplacbrkesadimqlcdqsbpqdcfotdpfwjhcdsqolungoeiwnqfbrwutdcsacmicqqlgvusplnmsqcxrxhsrpuetsmcohpntbicqpxqokpndjbkraicfmthbbxfkmcvksbmxplbcalkcskixaswxrewthtmdjhrwjdbtpqvenicfklibxnfnuwpternjevhiixjvhgvscowwjwvjocpkhbnrqxcuxvjoh...

output:

861490076

result:

ok single line: '861490076'

Test #11:

score: 0
Accepted
time: 2ms
memory: 16156kb

input:

1 114514
a

output:

114514

result:

ok single line: '114514'

Test #12:

score: 0
Accepted
time: 0ms
memory: 14124kb

input:

1 1
a

output:

1

result:

ok single line: '1'

Test #13:

score: 0
Accepted
time: 18ms
memory: 17624kb

input:

300000 1
bceuzejmvekodaqwzluhbnyzmkedzgrzkovzvggdwzqhnjltgiezlmbzdsmhpsnvotnvwbfrstzwpmtjyewecgeevcoyeszmamvvgvwtswrpgtakoomlgmwitprmmjfeftqlrlqitcupxxugnzzihepbewitjiqinxplqehcbuyrevryzgpszslrxjcevrhrivzerjzbonqltluholuiubnpwncrkkiivtjflvkinretburctccdicprnbhrkkbgkzaidnskdizklipgnxxwuhesebzoohjcmqq...

output:

78188321

result:

ok single line: '78188321'

Test #14:

score: 0
Accepted
time: 80ms
memory: 18512kb

input:

300000 1919810
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

954252672

result:

ok single line: '954252672'

Test #15:

score: 0
Accepted
time: 2ms
memory: 14200kb

input:

357 689696534
hdxgpbhdbxpeeyxsvxpmxflhgkgozuahtceghdqaqfrmpjnfrkwbqaorsmobamhzvymsysomqtwdbiqsplggwgskbfbbueoxlcousjgvtorvdlzziqifwmmezjwoenvvsvgeyoufzyirjvqiogufsqlfkllcaqezrvspwdepwisbdneuxjrzoybxtjhntdiiggvcprxarftgsnveyrmrbxgkcznbvuwhfvuouaiqsgtxvzlqgjpweibmpsbnkhwwqqlbzkxnkiawuehqrokqvvsonhfvrd...

output:

726994398

result:

ok single line: '726994398'

Extra Test:

score: 0
Extra Test Passed