ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#213817 | #2411. 三元组 | Origami_Tobiichi | 100 | 3775ms | 27572kb | C++11 | 1.8kb | 2024-11-13 20:26:37 | 2024-11-13 23:06:15 |
answer
#include <bits/stdc++.h>
using namespace std;
#define file(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout)
typedef long long ll;
const int N = 2e6 + 5, mod = 998244353;
int n, mxr, mid, l, ans, L, R;
int len[N], p[N], s[N], c1[N], c2[N];
char a[N], c[N];
void init()
{
for (int i = 1; i <= l; i++)
{
L = (i + 1) / 2, R = L + (len[i] / 2);
c1[L] = (c1[L] + i) % mod, c1[R] = (c1[R] - i + mod) % mod;
c2[L] = (c2[L] + 1) % mod, c2[R] = (c2[R] - 1 + mod) % mod;
}
for (int i = 1; i <= n; i++)
{
c1[i] = (c1[i - 1] + c1[i]) % mod;
c2[i] = (c2[i - 1] + c2[i]) % mod;
p[i] = (c1[i] - (ll)c2[i] * i % mod + mod) % mod;
}
for (int i = 1; i <= n + 1; i++)
c1[i] = c2[i] = 0;
for (int i = 1; i <= l; i++)
{
R = i / 2 + 1, L = R - (len[i] / 2);
c1[L] = (c1[L] + i) % mod, c1[R] = (c1[R] - i + mod) % mod;
c2[L] = (c2[L] + 1) % mod, c2[R] = (c2[R] - 1 + mod) % mod;
}
for (int i = 1; i <= n; i++)
{
c1[i] = (c1[i - 1] + c1[i]) % mod;
c2[i] = (c2[i - 1] + c2[i]) % mod;
s[i] = (c1[i] - (ll)c2[i] * i % mod + mod) % mod;
}
for (int i = 1; i <= n + 1; i++)
c1[i] = c2[i] = 0;
}
void manacher()
{
l = mxr = mid = 0;
c[++l] = '#';
for (int i = 1; i <= n; i++)
c[++l] = a[i], c[++l] = '#';
c[0] = '&', c[l + 1] = '|';
for (int i = 1; i <= l; i++)
{
if (i <= mxr)
len[i] = min(len[(mid << 1) - i], mxr - i + 1);
else
len[i] = 1;
while (c[i + len[i]] == c[i - len[i]])
len[i]++;
if (i + len[i] - 1 >= mxr)
mxr = i + len[i] - 1, mid = i;
}
}
signed main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%s", a + 1), n = strlen(a + 1);
manacher(), init();
ans = 0;
for (int i = 1; i < n; i++)
ans = (ans + (ll)p[i] * s[i + 1]) % mod;
printf("%d\n", ans);
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1212kb
input:
10 kyynjrttqngurtcvcjnnuqmstrntnpghrqqqp lqfnqzykyzzynqnqyywzzwwfnyzlwykznyfhyknfnk fuhjuhhuhuqjuuqu...
output:
27169 35530 31188 37732 65217 28457 133147 22985 43141 10759
result:
ok 10 lines
Test #2:
score: 10
Accepted
time: 0ms
memory: 1212kb
input:
10 eedleeeldeededlllleldleeeleleddleellele kllrnnjqjniqqknjmlfcirjyrycfrkyqqjrky uksfueafjuarusziepe...
output:
66808 20895 14900 37820 39914 38054 29364 37426 38775 29747
result:
ok 10 lines
Test #3:
score: 10
Accepted
time: 1ms
memory: 1220kb
input:
10 aaqzqvvvvzaqvazzvqqzqzavaaavvqaqqqvaqavvavvaavzvqzavaqvzvaazavqavazzvqvqazzvzvqqaqaaqqazqaqqzzzza...
output:
6230886 3556080 11774834 3833447 8206626 3621091 5300328 6484259 3025216 18509610
result:
ok 10 lines
Test #4:
score: 10
Accepted
time: 0ms
memory: 1232kb
input:
10 bsppzzcusncccbbpgguszngssnzncsnzpppbpuuczgcbucpupcubbzubsncncpbgbuzungnznsnpncpbugzcpguungzgcnbng...
output:
559443824 305794405 414279981 912202469 497470943 263140764 422669314 204178180 579056344 460822521
result:
ok 10 lines
Test #5:
score: 10
Accepted
time: 2ms
memory: 1232kb
input:
10 pzrpbfgjbnqhbpzohubzunqjnujfbfgazjqeaqhjgppqnogagegebuebhbeoeboouoojhbhaahjooggrozeephgqfrzrfrpjz...
output:
442803205 483459867 245377898 502317569 156660068 301473465 396310915 489306288 862513697 753896393
result:
ok 10 lines
Test #6:
score: 10
Accepted
time: 675ms
memory: 1212kb
input:
100000 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
341665830 471661 1999742 543480 459540 202296822 191363172 1241848 713235 369157 575809 170913820 68...
result:
ok 100000 lines
Test #7:
score: 10
Accepted
time: 780ms
memory: 1236kb
input:
10000 iqtuiwnrdznudrwdznuwoyhzhhmiqytqhdqjuhihyuyrmwqurmdzdwiidomqrihqrjzyjwytjhznuwuhiojnhiduhytjir...
output:
452745570 395658802 415729637 581286624 608938037 896800719 444684505 913683462 444333468 228535301 ...
result:
ok 10000 lines
Test #8:
score: 10
Accepted
time: 756ms
memory: 1472kb
input:
1000 sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
845573779 254782300 56185577 239721206 427653199 812292186 496897443 160197728 268511769 327773907 7...
result:
ok 1000 lines
Test #9:
score: 10
Accepted
time: 855ms
memory: 3848kb
input:
100 yuuxiorshssxoiyxrsxyyyuxsuyuhsruhxisoyiuuixhrsxuxyyxxosihhyisxxohoyiiurxhixrruryiihxhsxhxuhoroou...
output:
732636589 377635994 204944545 800901731 855220417 505651421 500433866 804284443 619658341 415348374 ...
result:
ok 100 lines
Test #10:
score: 10
Accepted
time: 706ms
memory: 27572kb
input:
10 qvvvvqqgqgvvvgqvgqvqqwqgwqvqggvgqqqgqvwwggwwqqqqqwvwqggqvgqqvvvvvwqvqvvgvvqgvwqggwqqvvwwvvgwwwgqg...
output:
277639311 181813441 852565296 302618524 261112096 362781838 797779507 470139835 806725645 543544402
result:
ok 10 lines
Extra Test:
score: 0
Extra Test Passed