ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213847 | #2411. 三元组 | N | 90 | 1875ms | 34468kb | C++11 | 3.4kb | 2024-11-13 21:55:35 | 2024-11-13 23:09:26 |
answer
//
// na 2411.cpp
// Competitive Programming
//
// Created by m2 on 2024/11/13.
//
#include <stdio.h>
#include <iostream>
using namespace std;
typedef long long int ll;
const int maxn = 1e6 + 5, mod = 998244353;
int t, n, m, d[maxn * 2];
char s[maxn * 2];
int lbs[maxn], lss[maxn], rbs[maxn], rss[maxn], ls[maxn], rs[maxn];
// seq[i] = -i
inline void add(int &a, int b){
if((a += b) >= mod)
a -= mod;
}
inline void mnu(int &a, int b){
if((a -= b) < 0)
a += mod;
}
inline int mul(int a, int b){
return ll(a) * b % mod;
}
inline void clear_ss(){
for(int i = 1; i <= n; ++i)
lbs[i] = lss[i] = rbs[i] = rss[i] = 0;
}
inline void pseq(int *seq){
for(int i = 1; i <= n; ++i)
cerr << seq[i] << ' ';
}
inline void calc_sum(){
for(int i = 2; i <= n; ++i){
add(lss[i], lss[i - 1]);
add(lbs[i], lbs[i - 1]);
add(rss[i], rss[i - 1]);
add(rbs[i], rbs[i - 1]);
}
// cerr << "l seq sum: ";
// pseq(lss);
// cerr << endl << "l base sum: ";
// pseq(lbs);
// cerr << endl << "r seq sum: ";
// pseq(rss);
// cerr << endl << "r base sum: ";
// pseq(rbs);
// cerr << endl;
for(int i = 1; i <= n; ++i){
ls[i] = mul(mod - i, lss[i]);
add(ls[i], lbs[i]);
rs[i] = mul(mod - i, rss[i]);
add(rs[i], rbs[i]);
}
// cerr << "ls: ";
// pseq(ls);
// cerr << endl << "rs: ";
// pseq(rs);
// cerr << endl;
}
inline void add_laz(int lt, int rt){
if(lt > rt)
return;
// cerr << "************* add_laz: " << lt << " <-> " << rt << endl;
int mid = (lt + rt) >> 1;
if((rt - lt) & 1){ // even
++mid;
add(lss[lt], 1);
add(lbs[lt], lt + rt);
mnu(lss[mid], 1);
mnu(lbs[mid], lt + rt);
add(rss[mid], 1);
add(rbs[mid], mid + mid - 1);
mnu(rss[rt + 1], 1);
mnu(rbs[rt + 1], mid + mid - 1);
}else{ // odd
add(lss[lt], 1);
add(lbs[lt], lt + rt);
mnu(lss[mid + 1], 1);
mnu(lbs[mid + 1], lt + rt);
add(rss[mid], 1);
add(rbs[mid], mid + mid);
mnu(rss[rt + 1], 1);
mnu(rbs[rt + 1], mid + mid);
}
// calc_sum();
// clear_ss();
}
inline void solve(){
cin >> s;
n = 0;
while(s[++n]);
clear_ss();
for(int i = n - 1; i >= 0; --i)
s[i << 1 | 1] = s[i];
for(int i = 1; i < n; ++i)
s[i << 1] = '#';
m = n * 2;
s[0] = s[m] = '#';
// for(int i = 0; i <= m; ++i)
// cerr << s[i];
// cerr << endl;
int l = -1, r = -1, k, p, rd;
for(int i = 0; i <= m; ++i){
k = i > r? 1: min(d[l + r - i], r - i + 1);
while(i - k >= 0 && i + k <= m && s[i - k] == s[i + k])
++k;
d[i] = k;
p = (i + 1) >> 1;
rd = k >> 1;
if(i & 1){ // isalpha(s[i])
add_laz(p - rd + 1, p + rd - 1);
}else{ // s[i] = '#'
add_laz(p - rd + 1, p + rd);
}
--k;
if(i + k > r){
r = i + k;
l = i - k;
}
}
calc_sum();
int ans = 0;
for(int m = 1; m < n; ++m)
add(ans, mul(rs[m], ls[m + 1]));
cout << ans << endl;
}
int main(){
cin.tie(0)->sync_with_stdio(false);
cin >> t;
while(t--)
solve();
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1288kb
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: 1292kb
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: 0ms
memory: 1300kb
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: 1328kb
input:
10 bsppzzcusncccbbpgguszngssnzncsnzpppbpuuczgcbucpupcubbzubsncncpbgbuzungnznsnpncpbugzcpguungzgcnbng...
output:
559443824 305794405 414279981 912202469 497470943 263140764 422669314 204178180 579056344 460822521
result:
ok 10 lines
Test #5:
score: 10
Accepted
time: 0ms
memory: 1332kb
input:
10 pzrpbfgjbnqhbpzohubzunqjnujfbfgazjqeaqhjgppqnogagegebuebhbeoeboouoojhbhaahjooggrozeephgqfrzrfrpjz...
output:
442803205 483459867 245377898 502317569 156660068 301473465 396310915 489306288 862513697 753896393
result:
ok 10 lines
Test #6:
score: 0
Time Limit Exceeded
input:
100000 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
341665830 471661 1999742 543480 459540 202296822 191363172 1241848 713235 369157 575809 170913820 68...
result:
Test #7:
score: 10
Accepted
time: 461ms
memory: 1328kb
input:
10000 iqtuiwnrdznudrwdznuwoyhzhhmiqytqhdqjuhihyuyrmwqurmdzdwiidomqrihqrjzyjwytjhznuwuhiojnhiduhytjir...
output:
452745570 395658802 415729637 581286624 608938037 896800719 444684505 913683462 444333468 228535301 ...
result:
ok 10000 lines
Test #8:
score: 10
Accepted
time: 453ms
memory: 1624kb
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: 525ms
memory: 4612kb
input:
100 yuuxiorshssxoiyxrsxyyyuxsuyuhsruhxisoyiuuixhrsxuxyyxxosihhyisxxohoyiiurxhixrruryiihxhsxhxuhoroou...
output:
732636589 377635994 204944545 800901731 855220417 505651421 500433866 804284443 619658341 415348374 ...
result:
ok 100 lines
Test #10:
score: 10
Accepted
time: 436ms
memory: 34468kb
input:
10 qvvvvqqgqgvvvgqvgqvqqwqgwqvqggvgqqqgqvwwggwwqqqqqwvwqggqvgqqvvvvvwqvqvvgvvqgvwqggwqqvvwwvvgwwwgqg...
output:
277639311 181813441 852565296 302618524 261112096 362781838 797779507 470139835 806725645 543544402
result:
ok 10 lines