QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245984 | #5474. Incredibly Cute Penguin Chicks | Fireball0424# | WA | 699ms | 51396kb | C++14 | 3.1kb | 2023-11-10 15:04:36 | 2023-11-10 15:04:36 |
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;
int pre[N * 2 + 5][3];
void add(int pos, int val, int tp){
for (int i = pos; i < N * 2 + 5; i += i & -i) {
pre[i][tp] += val;
if (pre[i][tp] >= mod) pre[i][tp] -= mod;
}
}
int query(int pos, int tp){
int ans = 0;
for (int i = pos; i; i -= i & -i){
ans += pre[i][tp];
if (ans >= mod) ans -= mod;
}
return ans;
}
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<pair<int, int>> all[3];
auto id = [&](int x, int pos, int t){
return lower_bound(all[t].begin(), all[t].end(), make_pair(x, pos)) - all[t].begin() + 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;
all[0].push_back({x1, y1});
all[1].push_back({x2, y2});
all[2].push_back({x3, y3});
}
all[0].push_back({N + 2, N + 2});
all[1].push_back({N + 2, N + 2});
all[2].push_back({N + 2, N + 2});
sort(all[0].begin(), all[0].end());
sort(all[1].begin(), all[1].end());
sort(all[2].begin(), all[2].end());
add(id(N + 2, N + 2, 0), 1, 0);
add(id(N + 2, N + 2, 1), 1, 1);
add(id(N + 2, N + 2, 2), 1, 2);
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 = query(id(x1, y1, 0) - 1, 0) - query(id(x1, 0, 0) - 1, 0);
res += query(id(x2, y2, 1) - 1, 1) - query(id(x2, 0, 1) - 1, 1);
if(res >= mod) res -= mod;
res += query(id(x3, y3, 2) - 1, 2) - query(id(x3, 0, 2) - 1, 2);
if(res >= mod) res -= mod;
add(id(x1, y1, 0), res, 0);
add(id(x2, y2, 1), res, 1);
add(id(x3, y3, 2), res, 2);
//db(i, res, query(id(x1, y1, 0) - 1, 0) - query(id(x1, 0, 0) - 1, 0), query(id(x2, y2, 1) - 1, 1) - query(id(x2, 0, 1) - 1, 1), query(id(x3, y3, 2) - 1, 2) - query(id(x3, 0, 2) - 1, 2));
if(i == n) db(res);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3516kb
input:
ICPC
output:
2
result:
ok single line: '2 '
Test #2:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
CCCIIIPPP
output:
69
result:
ok single line: '69 '
Test #3:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
PICCICCIPPI
output:
24
result:
ok single line: '24 '
Test #4:
score: -100
Wrong Answer
time: 699ms
memory: 51396kb
input:
PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...
output:
198859679
result:
wrong answer 1st lines differ - expected: '216523282', found: '198859679 '