QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#746521 | #9747. 字符串复制 | wsyear# | AC ✓ | 407ms | 28184kb | C++20 | 3.9kb | 2024-11-14 14:53:11 | 2024-11-14 14:53:14 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
template <int P>
class mod_int {
using Z = mod_int;
private:
static int mo(int x) { return x < 0 ? x + P : x; }
public:
int x;
int val() const { return x; }
mod_int() : x(0) {}
template <class T>
mod_int(const T &x_) : x(x_ >= 0 && x_ < P ? static_cast<int>(x_) : mo(static_cast<int>(x_ % P))) {}
bool operator==(const Z &rhs) const { return x == rhs.x; }
bool operator!=(const Z &rhs) const { return x != rhs.x; }
Z operator-() const { return Z(x ? P - x : 0); }
Z pow(long long k) const {
Z res = 1, t = *this;
while (k) {
if (k & 1) res *= t;
if (k >>= 1) t *= t;
}
return res;
}
Z &operator++() {
x < P - 1 ? ++x : x = 0;
return *this;
}
Z &operator--() {
x ? --x : x = P - 1;
return *this;
}
Z operator++(int) {
Z ret = x;
x < P - 1 ? ++x : x = 0;
return ret;
}
Z operator--(int) {
Z ret = x;
x ? --x : x = P - 1;
return ret;
}
Z inv() const { return pow(P - 2); }
Z &operator+=(const Z &rhs) {
(x += rhs.x) >= P && (x -= P);
return *this;
}
Z &operator-=(const Z &rhs) {
(x -= rhs.x) < 0 && (x += P);
return *this;
}
Z &operator*=(const Z &rhs) {
x = 1ULL * x * rhs.x % P;
return *this;
}
Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
#define setO(T, o) \
friend T operator o(const Z &lhs, const Z &rhs) {\
Z res = lhs; \
return res o## = rhs; \
}
setO(Z, +) setO(Z, -) setO(Z, *) setO(Z, /)
#undef setO
};
const int P = 998244353;
using Z = mod_int<P>;
const int maxn = 1000010;
namespace SA {
// init: len = m, |char| = sigma, string = a[]
int m, sigma, a[maxn], rnk[maxn], sa[maxn], h[maxn], cnt[maxn], p[maxn];
void SA_sort() {
rep (i, 1, sigma) cnt[i] = 0;
rep (i, 1, m) cnt[rnk[i]] += 1;
rep (i, 1, sigma) cnt[i] += cnt[i - 1];
per (i, m, 1) sa[cnt[rnk[p[i]]]--] = p[i];
}
void Get_SA() {
rep (i, 1, m) rnk[i] = a[i], p[i] = i;
SA_sort();
for (int len = 1, tot = 0; tot < m; sigma = tot, len <<= 1) {
tot = 0;
per (i, m, m - len + 1) p[++tot] = i;
rep (i, 1, m) if (sa[i] > len) p[++tot] = sa[i] - len;
SA_sort();
rep (i, 1, m) p[i] = rnk[i];
rnk[sa[1]] = tot = 1;
rep (i, 2, m) {
if (p[sa[i - 1]] == p[sa[i]] &&
p[sa[i - 1] + len] == p[sa[i] + len]) rnk[sa[i]] = tot;
else rnk[sa[i]] = ++tot;
}
}
rep (i, 1, m) rnk[sa[i]] = i;
}
void Get_Height() {
int k = 0;
rep (i, 1, m) {
if (rnk[i] == 1) continue;
k = max(k - 1, 0);
int j = sa[rnk[i] - 1];
while (max(i, j) + k <= m && a[i + k] == a[j + k]) k++;
h[rnk[i]] = k;
}
}
}
ll calc(string s) {
int n = s.length();
SA::m = n, SA::sigma = 26;
rep (i, 1, n) SA::a[i] = s[i - 1] - 'a' + 1;
SA::Get_SA(), SA::Get_Height();
ll ans = 1ll * n * (n + 1) / 2;
rep (i, 1, n) ans -= SA::h[i];
return ans;
}
int n, m;
string s;
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cin >> n >> m >> s;
Z a = calc(s), b = calc(s + s), c = calc(s + s + s);
if (m == 1) cout << a.val() << '\n';
else if (m == 2) cout << b.val() << '\n';
else cout << (b + (c - b) * (m - 2)).val() << '\n';
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 13992kb
input:
6 2 mantle
output:
57
result:
ok single line: '57'
Test #2:
score: 0
Accepted
time: 2ms
memory: 13992kb
input:
12 1919810 ifamjlifamjl
output:
138226305
result:
ok single line: '138226305'
Test #3:
score: 0
Accepted
time: 0ms
memory: 13832kb
input:
13 935330878 aabbbbababbaa
output:
348310505
result:
ok single line: '348310505'
Test #4:
score: 0
Accepted
time: 407ms
memory: 27944kb
input:
300000 1000000000 rqwcfnskpxmdplyemxtntenuvjcbtggljuravmoaipbujlseqtuakblnqzbirxowfaeykxwldpeovyuuvjvskbllmtdlsfswoklvdpuuujryuvzbabieklgkcbqdocbmmwsjlfiqxvwocsexuldtiaucurmiewfrggbnbfmxqtaabxnbzcjnavvuuvowvyazzmgtdwvjlmwxpxontrusqgipfvfsjtckxdrloofzmjxxhlexhqcjchgryycbybcnmbjsaffaeaitkalawjuporbnzo...
output:
478922465
result:
ok single line: '478922465'
Test #5:
score: 0
Accepted
time: 0ms
memory: 13832kb
input:
3000 546279171 ddcaddabbadcdbcbacaddcabcbdcadbdadabdbadbbbbbbbcbddddbbbcdddcabcabbacadcbddbcddaabcacbcdcbccccbddababbbcacacdcaddaadacbcabbcccdbbabbddcdccabccaabbbdbaacccddccbbdbadacdcaaabbddccdbacddddaacaacbadcdacdcaddcdbcbdcbccaabadabcdcdaddaadcdadbaabacddacbcbbdaacdaccdadcdcabaacabcbdcacdacbcccdad...
output:
375109583
result:
ok single line: '375109583'
Test #6:
score: 0
Accepted
time: 12ms
memory: 16240kb
input:
20000 713238600 ddaceddaaaaaebbaccedaaaacdedadceecbcedaeabcaaecbdaebebdbdebebdddbdbabadabdddaaacdbccbccecdeaebcdabcacdbedacadcccecaddcaeeecbbabcbbccebceacdeeadbbcdcceaebaecaccbbabbceedbcedbbbbbbdeaadaaeaaecabeddbdeeaaeabcbaedbedeabbdecbacaabdadbabbdacabdcdaecaaaabecbdddeabadaacbddceecbeebcadacdbcedd...
output:
793179337
result:
ok single line: '793179337'
Test #7:
score: 0
Accepted
time: 240ms
memory: 26224kb
input:
200000 432588167 gfeaccabbeccbfbcafcdfebabeebfgdccbgbcbddcfacccedebcagdccagafefdcbdgfcbadaeffcdaebbdadgfgdefdgbgaeeadfcebbeaaegbbcbfdeegdcfdgebddadaceaacggcgaecddfdcgbgeaffgbgfcacdddcbgaddecceaefcbddebgceeegbceceegcaaadgccdbcffebaaeddcdgbgagbbcfffaabafcagfaabfadcbadggbdcfebgbagggagdfbccdbeafgcbegfcf...
output:
68059895
result:
ok single line: '68059895'
Test #8:
score: 0
Accepted
time: 393ms
memory: 28184kb
input:
300000 4405849 bbbabbbbaabaabaabbbaabbaaaabaaabbabbbbabbbbbabbbbababaaabbaaababbbaaabbbabbbbbaababbaabaaabbabbaaaaaabbabaaabbbbaabaabbbaaabaaaababbabbbbabbbbaaaaaaabababaaabababaabababaaaabbababbbbaabbbaabbabaabaabaaabbababbaababbaaabaaabbbababbabaababbabbabbabaabbbbbababbabaabbbaabaabbaabaababababb...
output:
147294182
result:
ok single line: '147294182'
Test #9:
score: 0
Accepted
time: 400ms
memory: 27936kb
input:
300000 59262767 tvjfbbccnjyudccwhwkvmfqvuoxqqktkbiqqtwfdwgxcqiljnsbyelzztivlpuylpcpupeccakwmhfjtlayinlvzptznmyqgtgsfrbojfsdwpqlxyhcvhyvioaeccqqbtjbvynwprudzgbtyknbugnbhcbmwkmsfokfmbnyxmidzshdsxibmhetswuyumbiedddkibvilqlgunananvbsiukuwewuibczodpdarorttepvewabnxslnpreoitjikgfyurecxqulvbzyzqagprzybrwln...
output:
638033683
result:
ok single line: '638033683'
Test #10:
score: 0
Accepted
time: 399ms
memory: 28024kb
input:
298942 948827395 eahqgctdomejjtldhbimwmmevmapsbmtvsrvlhhftqqnmddwgsskutelqwedplacbrkesadimqlcdqsbpqdcfotdpfwjhcdsqolungoeiwnqfbrwutdcsacmicqqlgvusplnmsqcxrxhsrpuetsmcohpntbicqpxqokpndjbkraicfmthbbxfkmcvksbmxplbcalkcskixaswxrewthtmdjhrwjdbtpqvenicfklibxnfnuwpternjevhiixjvhgvscowwjwvjocpkhbnrqxcuxvjoh...
output:
861490076
result:
ok single line: '861490076'
Test #11:
score: 0
Accepted
time: 0ms
memory: 11672kb
input:
1 114514 a
output:
114514
result:
ok single line: '114514'
Test #12:
score: 0
Accepted
time: 1ms
memory: 11976kb
input:
1 1 a
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 402ms
memory: 28048kb
input:
300000 1 bceuzejmvekodaqwzluhbnyzmkedzgrzkovzvggdwzqhnjltgiezlmbzdsmhpsnvotnvwbfrstzwpmtjyewecgeevcoyeszmamvvgvwtswrpgtakoomlgmwitprmmjfeftqlrlqitcupxxugnzzihepbewitjiqinxplqehcbuyrevryzgpszslrxjcevrhrivzerjzbonqltluholuiubnpwncrkkiivtjflvkinretburctccdicprnbhrkkbgkzaidnskdizklipgnxxwuhesebzoohjcmqq...
output:
78188321
result:
ok single line: '78188321'
Test #14:
score: 0
Accepted
time: 216ms
memory: 28028kb
input:
300000 1919810 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
954252672
result:
ok single line: '954252672'
Test #15:
score: 0
Accepted
time: 0ms
memory: 13836kb
input:
357 689696534 hdxgpbhdbxpeeyxsvxpmxflhgkgozuahtceghdqaqfrmpjnfrkwbqaorsmobamhzvymsysomqtwdbiqsplggwgskbfbbueoxlcousjgvtorvdlzziqifwmmezjwoenvvsvgeyoufzyirjvqiogufsqlfkllcaqezrvspwdepwisbdneuxjrzoybxtjhntdiiggvcprxarftgsnveyrmrbxgkcznbvuwhfvuouaiqsgtxvzlqgjpweibmpsbnkhwwqqlbzkxnkiawuehqrokqvvsonhfvrd...
output:
726994398
result:
ok single line: '726994398'
Extra Test:
score: 0
Extra Test Passed