QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#745731 | #9747. 字符串复制 | hhoppitree# | WA | 517ms | 29496kb | C++17 | 2.3kb | 2024-11-14 11:16:59 | 2024-11-14 11:16:59 |
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));
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;
}
详细
Test #1:
score: 100
Accepted
time: 10ms
memory: 19352kb
input:
6 2 mantle
output:
57
result:
ok single line: '57'
Test #2:
score: 0
Accepted
time: 8ms
memory: 18628kb
input:
12 1919810 ifamjlifamjl
output:
138226305
result:
ok single line: '138226305'
Test #3:
score: 0
Accepted
time: 7ms
memory: 20192kb
input:
13 935330878 aabbbbababbaa
output:
348310505
result:
ok single line: '348310505'
Test #4:
score: 0
Accepted
time: 512ms
memory: 29408kb
input:
300000 1000000000 rqwcfnskpxmdplyemxtntenuvjcbtggljuravmoaipbujlseqtuakblnqzbirxowfaeykxwldpeovyuuvjvskbllmtdlsfswoklvdpuuujryuvzbabieklgkcbqdocbmmwsjlfiqxvwocsexuldtiaucurmiewfrggbnbfmxqtaabxnbzcjnavvuuvowvyazzmgtdwvjlmwxpxontrusqgipfvfsjtckxdrloofzmjxxhlexhqcjchgryycbybcnmbjsaffaeaitkalawjuporbnzo...
output:
478922465
result:
ok single line: '478922465'
Test #5:
score: 0
Accepted
time: 19ms
memory: 18440kb
input:
3000 546279171 ddcaddabbadcdbcbacaddcabcbdcadbdadabdbadbbbbbbbcbddddbbbcdddcabcabbacadcbddbcddaabcacbcdcbccccbddababbbcacacdcaddaadacbcabbcccdbbabbddcdccabccaabbbdbaacccddccbbdbadacdcaaabbddccdbacddddaacaacbadcdacdcaddcdbcbdcbccaabadabcdcdaddaadcdadbaabacddacbcbbdaacdaccdadcdcabaacabcbdcacdacbcccdad...
output:
375109583
result:
ok single line: '375109583'
Test #6:
score: 0
Accepted
time: 31ms
memory: 21352kb
input:
20000 713238600 ddaceddaaaaaebbaccedaaaacdedadceecbcedaeabcaaecbdaebebdbdebebdddbdbabadabdddaaacdbccbccecdeaebcdabcacdbedacadcccecaddcaeeecbbabcbbccebceacdeeadbbcdcceaebaecaccbbabbceedbcedbbbbbbdeaadaaeaaecabeddbdeeaaeabcbaedbedeabbdecbacaabdadbabbdacabdcdaecaaaabecbdddeabadaacbddceecbeebcadacdbcedd...
output:
793179337
result:
ok single line: '793179337'
Test #7:
score: 0
Accepted
time: 294ms
memory: 28592kb
input:
200000 432588167 gfeaccabbeccbfbcafcdfebabeebfgdccbgbcbddcfacccedebcagdccagafefdcbdgfcbadaeffcdaebbdadgfgdefdgbgaeeadfcebbeaaegbbcbfdeegdcfdgebddadaceaacggcgaecddfdcgbgeaffgbgfcacdddcbgaddecceaefcbddebgceeegbceceegcaaadgccdbcffebaaeddcdgbgagbbcfffaabafcagfaabfadcbadggbdcfebgbagggagdfbccdbeafgcbegfcf...
output:
68059895
result:
ok single line: '68059895'
Test #8:
score: 0
Accepted
time: 468ms
memory: 29316kb
input:
300000 4405849 bbbabbbbaabaabaabbbaabbaaaabaaabbabbbbabbbbbabbbbababaaabbaaababbbaaabbbabbbbbaababbaabaaabbabbaaaaaabbabaaabbbbaabaabbbaaabaaaababbabbbbabbbbaaaaaaabababaaabababaabababaaaabbababbbbaabbbaabbabaabaabaaabbababbaababbaaabaaabbbababbabaababbabbabbabaabbbbbababbabaabbbaabaabbaabaababababb...
output:
147294182
result:
ok single line: '147294182'
Test #9:
score: 0
Accepted
time: 517ms
memory: 29448kb
input:
300000 59262767 tvjfbbccnjyudccwhwkvmfqvuoxqqktkbiqqtwfdwgxcqiljnsbyelzztivlpuylpcpupeccakwmhfjtlayinlvzptznmyqgtgsfrbojfsdwpqlxyhcvhyvioaeccqqbtjbvynwprudzgbtyknbugnbhcbmwkmsfokfmbnyxmidzshdsxibmhetswuyumbiedddkibvilqlgunananvbsiukuwewuibczodpdarorttepvewabnxslnpreoitjikgfyurecxqulvbzyzqagprzybrwln...
output:
638033683
result:
ok single line: '638033683'
Test #10:
score: 0
Accepted
time: 491ms
memory: 29496kb
input:
298942 948827395 eahqgctdomejjtldhbimwmmevmapsbmtvsrvlhhftqqnmddwgsskutelqwedplacbrkesadimqlcdqsbpqdcfotdpfwjhcdsqolungoeiwnqfbrwutdcsacmicqqlgvusplnmsqcxrxhsrpuetsmcohpntbicqpxqokpndjbkraicfmthbbxfkmcvksbmxplbcalkcskixaswxrewthtmdjhrwjdbtpqvenicfklibxnfnuwpternjevhiixjvhgvscowwjwvjocpkhbnrqxcuxvjoh...
output:
861490076
result:
ok single line: '861490076'
Test #11:
score: 0
Accepted
time: 0ms
memory: 18956kb
input:
1 114514 a
output:
114514
result:
ok single line: '114514'
Test #12:
score: 0
Accepted
time: 0ms
memory: 14056kb
input:
1 1 a
output:
1
result:
ok single line: '1'
Test #13:
score: -100
Wrong Answer
time: 28ms
memory: 19496kb
input:
300000 1 bceuzejmvekodaqwzluhbnyzmkedzgrzkovzvggdwzqhnjltgiezlmbzdsmhpsnvotnvwbfrstzwpmtjyewecgeevcoyeszmamvvgvwtswrpgtakoomlgmwitprmmjfeftqlrlqitcupxxugnzzihepbewitjiqinxplqehcbuyrevryzgpszslrxjcevrhrivzerjzbonqltluholuiubnpwncrkkiivtjflvkinretburctccdicprnbhrkkbgkzaidnskdizklipgnxxwuhesebzoohjcmqq...
output:
44999184206
result:
wrong answer 1st lines differ - expected: '78188321', found: '44999184206'