QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745733 | #9747. 字符串复制 | hhoppitree# | AC ✓ | 414ms | 29620kb | C++17 | 2.3kb | 2024-11-14 11:17:23 | 2024-11-14 11:17:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m;
char ch[N];
int x[N], y[N];
int cnt[N], SA[N];
int rk[N], height[N];
inline void RadixSort() {
for (register int i = 1; i <= m; ++i) {
cnt[i] = 0;
}
for (register int i = 1; i <= n; ++i) {
++cnt[x[i]];
}
for (register int i = 1; i <= m; ++i) {
cnt[i] += cnt[i - 1];
}
for (register int i = n; i >= 1; --i) {
SA[cnt[x[y[i]]]--] = y[i], y[i] = 0;
}
return;
}
long long calc(string s) {
n = s.size();
m = 127;
for (int i = 1; i <= n; ++i) ch[i] = s[i - 1];
for (register int i = 1; i <= n; ++i) {
x[i] = ch[i], y[i] = i;
}
RadixSort();
for (register int p = 1; p < n; p <<= 1) {
int tot = 0;
for (register int i = n - p + 1; i <= n; ++i) {
y[++tot] = i;
}
for (register int i = 1; i <= n; ++i) {
if (SA[i] > p) {
y[++tot] = SA[i] - p;
}
}
RadixSort();
swap(x, y);
tot = x[SA[1]] = 1;
for (register int i = 2; i <= n; ++i) {
if (y[SA[i]] == y[SA[i - 1]] && y[SA[i] + p] == y[SA[i - 1] + p]) {
x[SA[i]] = tot;
} else {
x[SA[i]] = (++tot);
}
}
if (tot == n) {
break;
}
m = tot;
}
for (register int i = 1; i <= n; ++i) {
rk[SA[i]] = i;
}
for (register int i = 1; i <= n; ++i) {
if (rk[i] == 1) {
continue;
}
int k = height[rk[i - 1]];
if (k) {
--k;
}
int j = SA[rk[i] - 1];
while (i + k <= n && j + k <= n && ch[i + k] == ch[j + k]) {
++k;
}
height[rk[i]] = k;
}
long long ans = 1ll * n * (n + 1) / 2;
for (register int i = 1; i <= n; ++i) {
ans -= height[i];
}
return ans;
}
signed main() {
const int P = 998244353;
int n, m; scanf("%d%d", &n, &m);
string S; cin >> S;
if (m == 1) printf("%lld\n", calc(S) % P);
else {
long long s1 = calc(S + S), s2 = calc(S + S + S);
printf("%lld\n", (s1 % P + (s2 - s1) % P * ((m - 2) % P) % P) % P);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 9ms
memory: 20176kb
input:
6 2 mantle
output:
57
result:
ok single line: '57'
Test #2:
score: 0
Accepted
time: 9ms
memory: 18108kb
input:
12 1919810 ifamjlifamjl
output:
138226305
result:
ok single line: '138226305'
Test #3:
score: 0
Accepted
time: 6ms
memory: 20160kb
input:
13 935330878 aabbbbababbaa
output:
348310505
result:
ok single line: '348310505'
Test #4:
score: 0
Accepted
time: 412ms
memory: 29412kb
input:
300000 1000000000 rqwcfnskpxmdplyemxtntenuvjcbtggljuravmoaipbujlseqtuakblnqzbirxowfaeykxwldpeovyuuvjvskbllmtdlsfswoklvdpuuujryuvzbabieklgkcbqdocbmmwsjlfiqxvwocsexuldtiaucurmiewfrggbnbfmxqtaabxnbzcjnavvuuvowvyazzmgtdwvjlmwxpxontrusqgipfvfsjtckxdrloofzmjxxhlexhqcjchgryycbybcnmbjsaffaeaitkalawjuporbnzo...
output:
478922465
result:
ok single line: '478922465'
Test #5:
score: 0
Accepted
time: 19ms
memory: 19504kb
input:
3000 546279171 ddcaddabbadcdbcbacaddcabcbdcadbdadabdbadbbbbbbbcbddddbbbcdddcabcabbacadcbddbcddaabcacbcdcbccccbddababbbcacacdcaddaadacbcabbcccdbbabbddcdccabccaabbbdbaacccddccbbdbadacdcaaabbddccdbacddddaacaacbadcdacdcaddcdbcbdcbccaabadabcdcdaddaadcdadbaabacddacbcbbdaacdaccdadcdcabaacabcbdcacdacbcccdad...
output:
375109583
result:
ok single line: '375109583'
Test #6:
score: 0
Accepted
time: 31ms
memory: 19424kb
input:
20000 713238600 ddaceddaaaaaebbaccedaaaacdedadceecbcedaeabcaaecbdaebebdbdebebdddbdbabadabdddaaacdbccbccecdeaebcdabcacdbedacadcccecaddcaeeecbbabcbbccebceacdeeadbbcdcceaebaecaccbbabbceedbcedbbbbbbdeaadaaeaaecabeddbdeeaaeabcbaedbedeabbdecbacaabdadbabbdacabdcdaecaaaabecbdddeabadaacbddceecbeebcadacdbcedd...
output:
793179337
result:
ok single line: '793179337'
Test #7:
score: 0
Accepted
time: 250ms
memory: 28380kb
input:
200000 432588167 gfeaccabbeccbfbcafcdfebabeebfgdccbgbcbddcfacccedebcagdccagafefdcbdgfcbadaeffcdaebbdadgfgdefdgbgaeeadfcebbeaaegbbcbfdeegdcfdgebddadaceaacggcgaecddfdcgbgeaffgbgfcacdddcbgaddecceaefcbddebgceeegbceceegcaaadgccdbcffebaaeddcdgbgagbbcfffaabafcagfaabfadcbadggbdcfebgbagggagdfbccdbeafgcbegfcf...
output:
68059895
result:
ok single line: '68059895'
Test #8:
score: 0
Accepted
time: 374ms
memory: 29228kb
input:
300000 4405849 bbbabbbbaabaabaabbbaabbaaaabaaabbabbbbabbbbbabbbbababaaabbaaababbbaaabbbabbbbbaababbaabaaabbabbaaaaaabbabaaabbbbaabaabbbaaabaaaababbabbbbabbbbaaaaaaabababaaabababaabababaaaabbababbbbaabbbaabbabaabaabaaabbababbaababbaaabaaabbbababbabaababbabbabbabaabbbbbababbabaabbbaabaabbaabaababababb...
output:
147294182
result:
ok single line: '147294182'
Test #9:
score: 0
Accepted
time: 414ms
memory: 29340kb
input:
300000 59262767 tvjfbbccnjyudccwhwkvmfqvuoxqqktkbiqqtwfdwgxcqiljnsbyelzztivlpuylpcpupeccakwmhfjtlayinlvzptznmyqgtgsfrbojfsdwpqlxyhcvhyvioaeccqqbtjbvynwprudzgbtyknbugnbhcbmwkmsfokfmbnyxmidzshdsxibmhetswuyumbiedddkibvilqlgunananvbsiukuwewuibczodpdarorttepvewabnxslnpreoitjikgfyurecxqulvbzyzqagprzybrwln...
output:
638033683
result:
ok single line: '638033683'
Test #10:
score: 0
Accepted
time: 407ms
memory: 29480kb
input:
298942 948827395 eahqgctdomejjtldhbimwmmevmapsbmtvsrvlhhftqqnmddwgsskutelqwedplacbrkesadimqlcdqsbpqdcfotdpfwjhcdsqolungoeiwnqfbrwutdcsacmicqqlgvusplnmsqcxrxhsrpuetsmcohpntbicqpxqokpndjbkraicfmthbbxfkmcvksbmxplbcalkcskixaswxrewthtmdjhrwjdbtpqvenicfklibxnfnuwpternjevhiixjvhgvscowwjwvjocpkhbnrqxcuxvjoh...
output:
861490076
result:
ok single line: '861490076'
Test #11:
score: 0
Accepted
time: 3ms
memory: 18192kb
input:
1 114514 a
output:
114514
result:
ok single line: '114514'
Test #12:
score: 0
Accepted
time: 0ms
memory: 14036kb
input:
1 1 a
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 19ms
memory: 25576kb
input:
300000 1 bceuzejmvekodaqwzluhbnyzmkedzgrzkovzvggdwzqhnjltgiezlmbzdsmhpsnvotnvwbfrstzwpmtjyewecgeevcoyeszmamvvgvwtswrpgtakoomlgmwitprmmjfeftqlrlqitcupxxugnzzihepbewitjiqinxplqehcbuyrevryzgpszslrxjcevrhrivzerjzbonqltluholuiubnpwncrkkiivtjflvkinretburctccdicprnbhrkkbgkzaidnskdizklipgnxxwuhesebzoohjcmqq...
output:
78188321
result:
ok single line: '78188321'
Test #14:
score: 0
Accepted
time: 207ms
memory: 29620kb
input:
300000 1919810 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
954252672
result:
ok single line: '954252672'
Test #15:
score: 0
Accepted
time: 11ms
memory: 18412kb
input:
357 689696534 hdxgpbhdbxpeeyxsvxpmxflhgkgozuahtceghdqaqfrmpjnfrkwbqaorsmobamhzvymsysomqtwdbiqsplggwgskbfbbueoxlcousjgvtorvdlzziqifwmmezjwoenvvsvgeyoufzyirjvqiogufsqlfkllcaqezrvspwdepwisbdneuxjrzoybxtjhntdiiggvcprxarftgsnveyrmrbxgkcznbvuwhfvuouaiqsgtxvzlqgjpweibmpsbnkhwwqqlbzkxnkiawuehqrokqvvsonhfvrd...
output:
726994398
result:
ok single line: '726994398'
Extra Test:
score: 0
Extra Test Passed