QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#750910 | #9747. 字符串复制 | _LSA_ | WA | 531ms | 54292kb | C++14 | 2.2kb | 2024-11-15 16:18:35 | 2024-11-15 16:18:35 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
using namespace std;
ll read(){
ll X = 0 ,r = 1;
char ch = getchar();
while(!isdigit(ch) && ch != '-') ch = getchar();
if(ch == '-') r = -1,ch = getchar();
while(isdigit(ch)) X = X*10+ch-'0',ch = getchar();
return X*r;
}
const int N = 1e6+10;
const int mod = 998244353;
struct SA{
int n;
string ch;
int sa[N],rk[N],height[N],x[N],y[N],cnt[N];
void getsa(){
int m = 127;
for(int i=1;i<=n;i++) cnt[x[i] = ch[i]]++;
for(int i=1;i<=m;i++) cnt[i] += cnt[i-1];
for(int i=n;i>=1;i--) sa[cnt[x[i]]--] = i;
for(int k=1;k<=n;k*=2){
int p = 0;
for(int i=n-k+1;i<=n;i++) y[++p] = i;
for(int i=1;i<=n;i++) if(sa[i] > k) y[++p] = sa[i]-k;
for(int i=1;i<=m;i++) cnt[i] = 0;
for(int i=1;i<=n;i++) cnt[x[i]]++;
for(int i=2;i<=m;i++) cnt[i] += cnt[i-1];
for(int i=n;i>=1;i--) sa[cnt[x[y[i]]]--] = y[i];
swap(x,y); p = 1;
x[sa[1]] = 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] ? p : ++p;
m = p;
if(m >= n) break;
}
}
void getheight(){
for(int i=1;i<=n;i++) rk[sa[i]] = i;
int k = 0;
for(int i=1;i<=n;i++){
if(rk[i] == 1) continue;
if(k) k--;
int j = sa[rk[i]-1];
while(ch[i+k] == ch[j+k]) k++;
height[rk[i]] = k;
}
}
void init(string s){
n = s.size();
ch = " "+s;
getsa(); getheight();
}
ll getcnt(){
ll res = 1ll*n*(n-1)/2+n;
for(int i=2;i<=n;i++) res -= height[i];
return res;
}
}S2,S3;
int n;
ll ans,m;
int main(){
n = read(); m = read();
string s; cin >> s;
string s2 = s+s,s3 = s+s+s;
S2.init(s2); S3.init(s3);
ll cnt2 = S2.getcnt(),cnt3 = S3.getcnt();
ans = (cnt2+(cnt3-cnt2)%mod*(m-2)%mod)%mod;
cout << ans;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 8ms
memory: 32244kb
input:
6 2 mantle
output:
57
result:
ok single line: '57'
Test #2:
score: 0
Accepted
time: 5ms
memory: 34312kb
input:
12 1919810 ifamjlifamjl
output:
138226305
result:
ok single line: '138226305'
Test #3:
score: 0
Accepted
time: 6ms
memory: 32520kb
input:
13 935330878 aabbbbababbaa
output:
348310505
result:
ok single line: '348310505'
Test #4:
score: 0
Accepted
time: 531ms
memory: 53360kb
input:
300000 1000000000 rqwcfnskpxmdplyemxtntenuvjcbtggljuravmoaipbujlseqtuakblnqzbirxowfaeykxwldpeovyuuvjvskbllmtdlsfswoklvdpuuujryuvzbabieklgkcbqdocbmmwsjlfiqxvwocsexuldtiaucurmiewfrggbnbfmxqtaabxnbzcjnavvuuvowvyazzmgtdwvjlmwxpxontrusqgipfvfsjtckxdrloofzmjxxhlexhqcjchgryycbybcnmbjsaffaeaitkalawjuporbnzo...
output:
478922465
result:
ok single line: '478922465'
Test #5:
score: 0
Accepted
time: 12ms
memory: 34408kb
input:
3000 546279171 ddcaddabbadcdbcbacaddcabcbdcadbdadabdbadbbbbbbbcbddddbbbcdddcabcabbacadcbddbcddaabcacbcdcbccccbddababbbcacacdcaddaadacbcabbcccdbbabbddcdccabccaabbbdbaacccddccbbdbadacdcaaabbddccdbacddddaacaacbadcdacdcaddcdbcbdcbccaabadabcdcdaddaadcdadbaabacddacbcbbdaacdaccdadcdcabaacabcbdcacdacbcccdad...
output:
375109583
result:
ok single line: '375109583'
Test #6:
score: 0
Accepted
time: 19ms
memory: 36728kb
input:
20000 713238600 ddaceddaaaaaebbaccedaaaacdedadceecbcedaeabcaaecbdaebebdbdebebdddbdbabadabdddaaacdbccbccecdeaebcdabcacdbedacadcccecaddcaeeecbbabcbbccebceacdeeadbbcdcceaebaecaccbbabbceedbcedbbbbbbdeaadaaeaaecabeddbdeeaaeabcbaedbedeabbdecbacaabdadbabbdacabdcdaecaaaabecbdddeabadaacbddceecbeebcadacdbcedd...
output:
793179337
result:
ok single line: '793179337'
Test #7:
score: 0
Accepted
time: 285ms
memory: 51444kb
input:
200000 432588167 gfeaccabbeccbfbcafcdfebabeebfgdccbgbcbddcfacccedebcagdccagafefdcbdgfcbadaeffcdaebbdadgfgdefdgbgaeeadfcebbeaaegbbcbfdeegdcfdgebddadaceaacggcgaecddfdcgbgeaffgbgfcacdddcbgaddecceaefcbddebgceeegbceceegcaaadgccdbcffebaaeddcdgbgagbbcfffaabafcagfaabfadcbadggbdcfebgbagggagdfbccdbeafgcbegfcf...
output:
68059895
result:
ok single line: '68059895'
Test #8:
score: 0
Accepted
time: 437ms
memory: 53560kb
input:
300000 4405849 bbbabbbbaabaabaabbbaabbaaaabaaabbabbbbabbbbbabbbbababaaabbaaababbbaaabbbabbbbbaababbaabaaabbabbaaaaaabbabaaabbbbaabaabbbaaabaaaababbabbbbabbbbaaaaaaabababaaabababaabababaaaabbababbbbaabbbaabbabaabaabaaabbababbaababbaaabaaabbbababbabaababbabbabbabaabbbbbababbabaabbbaabaabbaabaababababb...
output:
147294182
result:
ok single line: '147294182'
Test #9:
score: 0
Accepted
time: 494ms
memory: 54292kb
input:
300000 59262767 tvjfbbccnjyudccwhwkvmfqvuoxqqktkbiqqtwfdwgxcqiljnsbyelzztivlpuylpcpupeccakwmhfjtlayinlvzptznmyqgtgsfrbojfsdwpqlxyhcvhyvioaeccqqbtjbvynwprudzgbtyknbugnbhcbmwkmsfokfmbnyxmidzshdsxibmhetswuyumbiedddkibvilqlgunananvbsiukuwewuibczodpdarorttepvewabnxslnpreoitjikgfyurecxqulvbzyzqagprzybrwln...
output:
638033683
result:
ok single line: '638033683'
Test #10:
score: 0
Accepted
time: 462ms
memory: 53148kb
input:
298942 948827395 eahqgctdomejjtldhbimwmmevmapsbmtvsrvlhhftqqnmddwgsskutelqwedplacbrkesadimqlcdqsbpqdcfotdpfwjhcdsqolungoeiwnqfbrwutdcsacmicqqlgvusplnmsqcxrxhsrpuetsmcohpntbicqpxqokpndjbkraicfmthbbxfkmcvksbmxplbcalkcskixaswxrewthtmdjhrwjdbtpqvenicfklibxnfnuwpternjevhiixjvhgvscowwjwvjocpkhbnrqxcuxvjoh...
output:
861490076
result:
ok single line: '861490076'
Test #11:
score: 0
Accepted
time: 3ms
memory: 34292kb
input:
1 114514 a
output:
114514
result:
ok single line: '114514'
Test #12:
score: 0
Accepted
time: 4ms
memory: 32276kb
input:
1 1 a
output:
1
result:
ok single line: '1'
Test #13:
score: -100
Wrong Answer
time: 484ms
memory: 53532kb
input:
300000 1 bceuzejmvekodaqwzluhbnyzmkedzgrzkovzvggdwzqhnjltgiezlmbzdsmhpsnvotnvwbfrstzwpmtjyewecgeevcoyeszmamvvgvwtswrpgtakoomlgmwitprmmjfeftqlrlqitcupxxugnzzihepbewitjiqinxplqehcbuyrevryzgpszslrxjcevrhrivzerjzbonqltluholuiubnpwncrkkiivtjflvkinretburctccdicprnbhrkkbgkzaidnskdizklipgnxxwuhesebzoohjcmqq...
output:
78188316
result:
wrong answer 1st lines differ - expected: '78188321', found: '78188316'