QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744810#9747. 字符串复制skip2004AC ✓170ms162008kbC++201.8kb2024-11-13 23:33:392024-11-13 23:33:41

Judging History

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

  • [2024-11-13 23:33:41]
  • 评测
  • 测评结果:AC
  • 用时:170ms
  • 内存:162008kb
  • [2024-11-13 23:33:39]
  • 提交

answer

#include<bits/stdc++.h>
namespace rgs = std::ranges;
using std::cin, std::cout;
using ll = long long;
using u64 = unsigned long long;
using db = double;
const int N = 300005 * 2 * 2;
const int mod = 998244353;
int c[N][26], mx[N], fail[N], tot = 1;
int append(int id, int w) {
	int p = id, now = ++tot;
	for(mx[now] = mx[p] + 1;p && !c[p][w];p = fail[p])
		c[p][w] = now;
	if(!p) fail[now] = 1;
	else {
		int q = c[p][w];
		if(mx[q] == mx[p] + 1) fail[now] = q;
		else {
			int x = ++tot; mx[x] = mx[p] + 1;
			memcpy(c[x], c[q], sizeof(c[0])), fail[x] = fail[q];
			for(fail[q] = fail[now] = x;p && c[p][w] == q;p = fail[p])
				c[p][w] = x;
		}
	}
	return now;
}
std::vector<int> e[N];
int vis[N];

std::vector<std::pair<int, int>> seq;
int n, m;
char s[N];

void dfs0(int x) {
	if(vis[x]) seq.emplace_back(x, vis[x]);
	for(int y : e[x]) {
		dfs0(y);
	}
}
int lca(int x, int y) {
	for(;x != y;) {
		if(mx[x] > mx[y]) std::swap(x, y);
		y = fail[y];
	}
	return x;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for(int i = 1;i <= n;++i) {
		cin >> s[i];
		s[i + n] = s[i];
	}
	const int p = n * std::min(m, 2);
	std::vector<int> id(p + 1);
	int x = 1;
	for(int i = 1;i <= p;++i) {
		id[i] = x = append(x, s[i] - 'a');
	}
	for(int i = 2;i <= tot;++i) e[fail[i]].push_back(i);
	for(int i = 1;i <= n;++i) {
		const int j = i + (m == 1 ? 0 : n);
		vis[id[j]] = j;
	}
	dfs0(1);
	ll ans = 0;
	for(int i = 1;i <= n;++i) {
		ans += i;
		ans += ll(m - 1) * n;
		ans %= mod;
	}
	for(int i = 1;i < n;++i) {
		auto [sx, x] = seq[i - 1];
		auto [sy, y] = seq[i];
		ll lcp = mx[lca(sx,  sy)];
		if(lcp >= n) lcp = std::min(x, y) + (ll) n * (m - 2);
		ans -= lcp;
		ans %= mod;
	}
	cout << (ans + mod) % mod << '\n';
}

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

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3580kb

input:

6 2
mantle

output:

57

result:

ok single line: '57'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

12 1919810
ifamjlifamjl

output:

138226305

result:

ok single line: '138226305'

Test #3:

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

input:

13 935330878
aabbbbababbaa

output:

348310505

result:

ok single line: '348310505'

Test #4:

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

input:

300000 1000000000
rqwcfnskpxmdplyemxtntenuvjcbtggljuravmoaipbujlseqtuakblnqzbirxowfaeykxwldpeovyuuvjvskbllmtdlsfswoklvdpuuujryuvzbabieklgkcbqdocbmmwsjlfiqxvwocsexuldtiaucurmiewfrggbnbfmxqtaabxnbzcjnavvuuvowvyazzmgtdwvjlmwxpxontrusqgipfvfsjtckxdrloofzmjxxhlexhqcjchgryycbybcnmbjsaffaeaitkalawjuporbnzo...

output:

478922465

result:

ok single line: '478922465'

Test #5:

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

input:

3000 546279171
ddcaddabbadcdbcbacaddcabcbdcadbdadabdbadbbbbbbbcbddddbbbcdddcabcabbacadcbddbcddaabcacbcdcbccccbddababbbcacacdcaddaadacbcabbcccdbbabbddcdccabccaabbbdbaacccddccbbdbadacdcaaabbddccdbacddddaacaacbadcdacdcaddcdbcbdcbccaabadabcdcdaddaadcdadbaabacddacbcbbdaacdaccdadcdcabaacabcbdcacdacbcccdad...

output:

375109583

result:

ok single line: '375109583'

Test #6:

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

input:

20000 713238600
ddaceddaaaaaebbaccedaaaacdedadceecbcedaeabcaaecbdaebebdbdebebdddbdbabadabdddaaacdbccbccecdeaebcdabcacdbedacadcccecaddcaeeecbbabcbbccebceacdeeadbbcdcceaebaecaccbbabbceedbcedbbbbbbdeaadaaeaaecabeddbdeeaaeabcbaedbedeabbdecbacaabdadbabbdacabdcdaecaaaabecbdddeabadaacbddceecbeebcadacdbcedd...

output:

793179337

result:

ok single line: '793179337'

Test #7:

score: 0
Accepted
time: 75ms
memory: 84224kb

input:

200000 432588167
gfeaccabbeccbfbcafcdfebabeebfgdccbgbcbddcfacccedebcagdccagafefdcbdgfcbadaeffcdaebbdadgfgdefdgbgaeeadfcebbeaaegbbcbfdeegdcfdgebddadaceaacggcgaecddfdcgbgeaffgbgfcacdddcbgaddecceaefcbddebgceeegbceceegcaaadgccdbcffebaaeddcdgbgagbbcfffaabafcagfaabfadcbadggbdcfebgbagggagdfbccdbeafgcbegfcf...

output:

68059895

result:

ok single line: '68059895'

Test #8:

score: 0
Accepted
time: 170ms
memory: 153248kb

input:

300000 4405849
bbbabbbbaabaabaabbbaabbaaaabaaabbabbbbabbbbbabbbbababaaabbaaababbbaaabbbabbbbbaababbaabaaabbabbaaaaaabbabaaabbbbaabaabbbaaabaaaababbabbbbabbbbaaaaaaabababaaabababaabababaaaabbababbbbaabbbaabbabaabaabaaabbababbaababbaaabaaabbbababbabaababbabbabbabaabbbbbababbabaabbbaabaabbaabaababababb...

output:

147294182

result:

ok single line: '147294182'

Test #9:

score: 0
Accepted
time: 78ms
memory: 112408kb

input:

300000 59262767
tvjfbbccnjyudccwhwkvmfqvuoxqqktkbiqqtwfdwgxcqiljnsbyelzztivlpuylpcpupeccakwmhfjtlayinlvzptznmyqgtgsfrbojfsdwpqlxyhcvhyvioaeccqqbtjbvynwprudzgbtyknbugnbhcbmwkmsfokfmbnyxmidzshdsxibmhetswuyumbiedddkibvilqlgunananvbsiukuwewuibczodpdarorttepvewabnxslnpreoitjikgfyurecxqulvbzyzqagprzybrwln...

output:

638033683

result:

ok single line: '638033683'

Test #10:

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

input:

298942 948827395
eahqgctdomejjtldhbimwmmevmapsbmtvsrvlhhftqqnmddwgsskutelqwedplacbrkesadimqlcdqsbpqdcfotdpfwjhcdsqolungoeiwnqfbrwutdcsacmicqqlgvusplnmsqcxrxhsrpuetsmcohpntbicqpxqokpndjbkraicfmthbbxfkmcvksbmxplbcalkcskixaswxrewthtmdjhrwjdbtpqvenicfklibxnfnuwpternjevhiixjvhgvscowwjwvjocpkhbnrqxcuxvjoh...

output:

861490076

result:

ok single line: '861490076'

Test #11:

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

input:

1 114514
a

output:

114514

result:

ok single line: '114514'

Test #12:

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

input:

1 1
a

output:

1

result:

ok single line: '1'

Test #13:

score: 0
Accepted
time: 59ms
memory: 69968kb

input:

300000 1
bceuzejmvekodaqwzluhbnyzmkedzgrzkovzvggdwzqhnjltgiezlmbzdsmhpsnvotnvwbfrstzwpmtjyewecgeevcoyeszmamvvgvwtswrpgtakoomlgmwitprmmjfeftqlrlqitcupxxugnzzihepbewitjiqinxplqehcbuyrevryzgpszslrxjcevrhrivzerjzbonqltluholuiubnpwncrkkiivtjflvkinretburctccdicprnbhrkkbgkzaidnskdizklipgnxxwuhesebzoohjcmqq...

output:

78188321

result:

ok single line: '78188321'

Test #14:

score: 0
Accepted
time: 48ms
memory: 162008kb

input:

300000 1919810
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

954252672

result:

ok single line: '954252672'

Test #15:

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

input:

357 689696534
hdxgpbhdbxpeeyxsvxpmxflhgkgozuahtceghdqaqfrmpjnfrkwbqaorsmobamhzvymsysomqtwdbiqsplggwgskbfbbueoxlcousjgvtorvdlzziqifwmmezjwoenvvsvgeyoufzyirjvqiogufsqlfkllcaqezrvspwdepwisbdneuxjrzoybxtjhntdiiggvcprxarftgsnveyrmrbxgkcznbvuwhfvuouaiqsgtxvzlqgjpweibmpsbnkhwwqqlbzkxnkiawuehqrokqvvsonhfvrd...

output:

726994398

result:

ok single line: '726994398'

Extra Test:

score: 0
Extra Test Passed