QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245771 | #5474. Incredibly Cute Penguin Chicks | Fireball0424# | ML | 637ms | 437876kb | C++14 | 3.4kb | 2023-11-10 11:45:27 | 2023-11-10 11:45:29 |
Judging History
answer
#pragma GCC optimizer("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
//#define int long long
#define ld long double
#define ull unsigned long long
#define fr first
#define fi first
#define sc second
#define se second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
using namespace std;
#ifndef fireball
#define tofu ios::sync_with_stdio(0); cin.tie(0);
#else
#define tofu freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
void db() {cout << '\n';}
template <typename T, typename ...U> void db(T a, U ...b) {cout << a << ' ', db(b...);}
const int N = 1e6 + 1;
const int mod = 998244353;
struct Seg{
int l, r, mid, sum = 0;
Seg *ch[2] = {nullptr, nullptr};
Seg(int lc, int rc) : l(lc), r(rc), mid(lc + rc >> 1){}
void pull(){
sum = (ch[0] ? ch[0] -> sum : 0) + (ch[1] ? ch[1] -> sum : 0);
if(sum >= mod) sum -= mod;
}
void add(int pos, int val){
if(l == r){
sum += val;
if(sum >= mod) sum -= mod;
return;
}
if(pos <= mid){
if(!ch[0]) ch[0] = new Seg(l, mid);
ch[0] -> add(pos, val);
}
if(pos > mid){
if(!ch[1]) ch[1] = new Seg(mid + 1, r);
ch[1] -> add(pos, val);
}
pull();
}
int query(int lc, int rc){
if(lc <= l and r <= rc) return sum;
int res = 0;
if(lc <= mid and ch[0]) {
res += ch[0] -> query(lc, rc);
if(res >= mod) res -= mod;
}
if(rc >= mid + 1 and ch[1]){
res += ch[1] -> query(lc, rc);
if(res >= mod) res -= mod;
}
return res;
}
};
signed main(){
tofu;
string s;
cin >> s;
int n = (int)s.length();
int pa[n + 1] = {}, pb[n + 1] = {}, pc[n + 1] = {};
for(int i = 0; i < n; ++i){
pa[i + 1] = pa[i] + (s[i] == 'I');
pb[i + 1] = pb[i] + (s[i] == 'C');
pc[i + 1] = pc[i] + (s[i] == 'P');
}
vector<Seg*> ab(2 * N + 5, nullptr), ac(2 * N + 5, nullptr), bc(2 * N + 5, nullptr);
for(int i = 0; i < 2 * N + 5; ++i){
ab[i] = new Seg(1, 2 * N + 5);
if (i == N + 2) ab[i] -> add(N + 2, 1);
}
for(int i = 0; i < 2 * N + 5; ++i){
ac[i] = new Seg(1, 2 * N + 5);
if (i == N + 2) ac[i] -> add(N + 2, 1);
}
for(int i = 0; i < 2 * N + 5; ++i){
bc[i] = new Seg(1, 2 * N + 5);
if (i == N + 2) bc[i] -> add(N + 2, 1);
}
for(int i = 1; i <= n; ++i){
int x1 = pa[i] - pb[i] + N + 2, y1 = pc[i] - pa[i] + N + 2;
int x2 = pa[i] - pc[i] + N + 2, y2 = pb[i] - pa[i] + N + 2;
int x3 = pb[i] - pc[i] + N + 2, y3 = pa[i] - pb[i] + N + 2;
int res = ab[x1] -> query(1, y1 - 1);
res += ac[x2] -> query(1, y2 - 1);
if(res >= mod) res -= mod;
res += bc[x3] -> query(1, y3 - 1);
if(res >= mod) res -= mod;
//db(i, res, bc[x3] -> query(1, y3 - 1));
ab[x1] -> add(y1, res);
ac[x2] -> add(y2, res);
bc[x3] -> add(y3, res);
// ab[pa[i - 1] - pb[i - 1] + N + 2] -> add(pc[i - 1] - pa[i - 1] + N + 2, res);
// ac[pa[i - 1] - pc[i - 1] + N + 2] -> add(pb[i - 1] - pa[i - 1] + N + 2, res);
// bc[pb[i - 1] - pc[i - 1] + N + 2] -> add(pa[i - 1] - pb[i - 1] + N + 2, res);
if(i == n) db(res);
}
}
详细
Test #1:
score: 100
Accepted
time: 98ms
memory: 331160kb
input:
ICPC
output:
2
result:
ok single line: '2 '
Test #2:
score: 0
Accepted
time: 80ms
memory: 331236kb
input:
CCCIIIPPP
output:
69
result:
ok single line: '69 '
Test #3:
score: 0
Accepted
time: 100ms
memory: 331180kb
input:
PICCICCIPPI
output:
24
result:
ok single line: '24 '
Test #4:
score: 0
Accepted
time: 622ms
memory: 425256kb
input:
PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...
output:
216523282
result:
ok single line: '216523282 '
Test #5:
score: 0
Accepted
time: 620ms
memory: 422576kb
input:
ICIPCICCIPIPIIPPCPCICICPCPCPIIICICPPICCICPIPCPCIIPPIPCCIPIPIPIICCICICCCIPPIIPCPPCIIICCICCCCCCPIPICCIPIICIICPIPCCICPPCCIPIPIICCCPCCIPCPPCCIIIIIPCIPIIPICIIIPIICCCIPPPIPICIIIICIIIPICIICPIPCCICIPCCIPICCCPPIPIIPICPPCPICIPIPPPPPCIPCCIPPICIPCICPCCCCPPIIIPCPICCICIPIIPICPIIIIPPPCPIIIPCCPPIIPPICPIIICCCPICPPIC...
output:
977504498
result:
ok single line: '977504498 '
Test #6:
score: 0
Accepted
time: 631ms
memory: 437876kb
input:
PPCCCICCIPPICCPCCCCIPPPIICPIPIPPPPIPPPPPPCPIPICCPCCPICPIPPPIIPIPIIPPCCPIICPPIIIPPCCCIIPCCIPCCCCCCIIIPIPCICCIICIIICCCCPCCICPPCCPCCIPICCPPIIPIIPIPCIIPIIPPPCCIPCPCCICCIPICPPPCIPPIPCCPCPCCIPIICCIPCCIPPCPCIPICIICPPICIIICIPIIIIIPCCCPPIPPPCIICIIIPPCIPCIPCIICCCCPIPCPICICPIPCPPIPIPICCPCCCCPCIPCPPCCIPCCCCCPII...
output:
785880133
result:
ok single line: '785880133 '
Test #7:
score: 0
Accepted
time: 591ms
memory: 414492kb
input:
ICIPCPIPCCCCCCCPCCPCCIPCPCPIPPCPIPCICPPIPPPPICPIIPPIICPICPICPPICICICCCIIPCPPCCICCCCPIICPPPIPIPCICPIPPPPCCPICPCPICICPPIIIICIICPPIPIIICCCCPIPIIPICCCIPCCPPCPPPPIIIIICIPCPCCPIIICICIPPCCPIPPCIIPCCCIIICPCIPCIIIIPCIIPCIICCCIPPIPPCIIPCICIPIIPICCICCPCPIICCCIPIICCCPIPPCCIIIICPPIICPCPCIPPPCPCICPPIPIPCCPIPPPIPI...
output:
687587235
result:
ok single line: '687587235 '
Test #8:
score: 0
Accepted
time: 637ms
memory: 425008kb
input:
IICCCIPIIIIIPICIICPCPCIICCIIICCCIIPICICCCPCPCPPPIIPIPPICIICICIPIICCICCIIIPCIICCPPIPICIPPCPCPCPIICCIIICIPPICCICPPIPPPPICPCPIPCCCPCPCPPPPIICPCIIIIIIIPIPIICICCPPIIPPCICPCPCIPCPICPPPICCICIICPPIPPPIPIPIPPCIPPCIPPCPPPIICICCCPICIPPIPCCPIIPPCIPPICCIIIPPPPPIIPPICPCPCIPPCCPCIIIPPICCCIIIIICIPPIIICPCIIICPPCPCPP...
output:
698376687
result:
ok single line: '698376687 '
Test #9:
score: 0
Accepted
time: 590ms
memory: 429340kb
input:
IIPICCCCIPPCCPICCIIPPPCIPCCPPIPIICICPCCIIPPCCCICICPPICCICPPIICIIPICPICIPPPPCPCCPIICCPPIPPCIIIIPICICICCIIPPCICCCCCPICPIPCPPCCPPICPICCCICCIPICCICPIICCPIPIPICCPPCCPCPCCPICCPICCCCCCIPIICPIPICICCPIIPIPICIICIPPPIPCICIPIPPICPICICPPICICCIPCIPPPCIPIIPPPIICICPPPIICCCPIIICIPIPPICICIPPPCCPCCIIPCCCPPPCPICPICPPCP...
output:
850857669
result:
ok single line: '850857669 '
Test #10:
score: -100
Memory Limit Exceeded
input:
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII...
output:
709758735