QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303158 | #7899. Say Hello to the Future | ucup-team173 | WA | 520ms | 45824kb | C++20 | 5.7kb | 2024-01-11 19:45:19 | 2024-01-11 19:45:20 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define For(x, y, z) for(int x = (y); x <= (z); x++)
#define Rep(x, y, z) for(int x = (y); x >= (z); x--)
using namespace std;
const int MAXN = 6e5 + 5, Mod = 998244353;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
inline char gc() {
return (pp1 == pp2) && (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2) ? EOF : *pp1++;
}
inline int read() {
int x = 0, ny = 1;
for(; nc = gc(), (nc < 48 || nc > 57) && nc != EOF; )
if(nc == '-') ny = -1;
if(nc < 0) return nc;
x = nc ^ 48;
for(; nc = gc(), (nc >= 48 && nc <= 57 && nc != EOF); )
x = (x << 3) + (x << 1) + (nc ^ 48);
return x * ny;
}
inline void add(int &x, int y) {
x += y, x >= Mod ? x -= Mod : 0;
}
inline int lowbit(int x) {
return x & -x;
}
int val[MAXN];
int n, f[MAXN], g[MAXN], a[MAXN];
int mxL[MAXN], mxR[MAXN];
void Add(int x, int v) {
for(x += 2e5; x < MAXN; x += lowbit(x)) add(val[x], v);
}
int ask(int x) {
int res = 0;
for(x += 2e5; x; x -= lowbit(x)) add(res, val[x]);
return res;
}
vector<pint> T[MAXN];
void calc1(int l, int r) {
if(l == r) {
if(a[l] == 1) add(f[l], f[l - 1]);
return ;
}
int mid = l + r >> 1;
calc1(l, mid);
mxL[mid + 1] = 0, mxR[mid] = 0;
Rep(i, mid, l) mxL[i] = max(mxL[i + 1], a[i]);
For(i, mid + 1, r) mxR[i] = max(mxR[i - 1], a[i]);
vector<int> p(0);
For(i, l, mid) p.push_back(i);
sort(p.begin(), p.end(), [&](int x, int y) {return x + mxL[x] < y + mxL[y];});
int now = 0;
For(i, mid + 1, r) {
while(now < p.size() && p[now] + mxL[p[now]] - 1 <= i)
Add(p[now], f[p[now] - 1]), now++;
add(f[i], ask(i - mxR[i] + 1));
}
while(now) now--, Add(p[now], Mod - f[p[now] - 1]);
calc1(mid + 1, r);
}
void calc2(int l, int r) {
if(l == r) {
if(a[l] == 1) add(g[l], g[l + 1]);
return ;
}
int mid = l + r >> 1;
calc2(mid + 1, r);
mxL[mid + 1] = 0, mxR[mid] = 0;
Rep(i, mid, l) mxL[i] = max(mxL[i + 1], a[i]);
For(i, mid + 1, r) mxR[i] = max(mxR[i - 1], a[i]);
vector<int> p(0);
For(i, mid + 1, r) p.push_back(i);
sort(p.begin(), p.end(), [&](int x, int y) {return x - mxR[x] > y - mxR[y];});
int now = 0;
Rep(i, mid, l) {
while(now < p.size() && p[now] - mxR[p[now]] + 1 >= i)
Add((n + 1) - p[now], g[p[now] + 1]), now++;
add(g[i], ask((n + 1) - (i + mxL[i] - 1)));
}
while(now) now--, Add((n + 1) - p[now], Mod - g[p[now] + 1]);
calc2(l, mid);
}
int del[MAXN];
int smxL[MAXN], smxR[MAXN];
int posL[MAXN], posR[MAXN];
void calc(int l, int r) {
if(l == r) {
if(a[l] != 1) del[l] = (del[l] + 1ll * f[l - 1] * g[l + 1]) % Mod;
return ;
}
int mid = l + r >> 1;
calc(l, mid), calc(mid + 1, r);
mxL[mid + 1] = smxL[mid + 1] = 0, mxR[mid] = smxR[mid] = 0;
Rep(i, mid, l) {
mxL[i] = mxL[i + 1], smxL[i] = smxL[i + 1], posL[i] = posL[i + 1];
if(a[i] > mxL[i]) smxL[i] = mxL[i], mxL[i] = a[i], posL[i] = i;
else if(a[i] > smxL[i]) smxL[i] = a[i];
}
For(i, mid + 1, r) {
mxR[i] = mxR[i - 1], smxR[i] = smxR[i - 1], posR[i] = posR[i - 1];
if(a[i] > mxR[i]) smxR[i] = mxR[i], mxR[i] = a[i], posR[i] = i;
else if(a[i] > smxR[i]) smxR[i] = a[i];
}
For(i, l, mid) T[i].clear();
For(i, l, mid) {
if(posL[i] == i) {
T[i].emplace_back(i, max(mxL[i + 1], 1));
} else if(mxL[i] != max(smxL[i], 1)){
T[i].emplace_back(posL[i], max(smxL[i], 1));
}
}
vector<int> p(0);
For(i, mid + 1, r) p.push_back(i);
sort(p.begin(), p.end(), [&](int x, int y) {return x - mxR[x] < y - mxR[y];});
int now = 0;
Rep(i, mid, l) {
while(now < p.size() && p[now] - mxR[p[now]] + 1 >= i)
Add((n + 1) - p[now], g[p[now] + 1]), now++;
for(auto [x, val] : T[i]) {
del[x] = (del[x] - 1ll * f[i - 1] * ask((n + 1) - (i + mxL[i] - 1)) % Mod + Mod) % Mod;
del[x] = (del[x] + 1ll * f[i - 1] * ask((n + 1) - (i + val - 1))) % Mod;
}
}
while(now) now--, Add((n + 1) - p[now], Mod - g[p[now] + 1]);
For(i, mid + 1, r) T[i].clear();
For(i, mid + 1, r) {
if(posR[i] == i) {
T[i].emplace_back(i, max(mxR[i - 1], 1));
} else if(mxR[i] != max(smxR[i], 1)){
T[i].emplace_back(posR[i], max(smxR[i], 1));
}
}
p.clear();
For(i, l, mid) p.push_back(i);
sort(p.begin(), p.end(), [&](int x, int y) {return x + mxL[x] < y + mxL[y];});
now = 0;
For(i, mid + 1, r) {
while(now < p.size() && p[now] + mxL[p[now]] - 1 <= i)
Add(p[now], f[p[now] - 1]), now++;
for(auto [x, val] : T[i]) {
del[x] = (del[x] - 1ll * g[i + 1] * ask(i - mxR[i] + 1) % Mod + Mod) % Mod;
del[x] = (del[x] + 1ll * g[i + 1] * ask(i - val + 1)) % Mod;
}
}
while(now) now--, Add(p[now], Mod - f[p[now] - 1]);
cout << '\n';
}
void solve() {
n = read();
For(i, 1, n) a[i] = read();
f[0] = 1, g[n + 1] = 1;
calc1(1, n), calc2(1, n), calc(1, n);
// For(i, 1, n) cout << f[i] << ' ' << g[i] << '\n';
For(i, 1, n) cout << (f[n] + del[i]) % Mod << ' ';
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
solve();
return 0;
}
/*
5
1 3 2 1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 34312kb
input:
5 1 3 2 1 2
output:
3 6 3 3 6
result:
ok 5 tokens
Test #2:
score: -100
Wrong Answer
time: 520ms
memory: 45824kb
input:
200000 15922 15391 11782 4758 1973 19909 16800 6438 3821 986 18599 2011 338 19886 12401 4169 11143 12665 3230 12565 15065 15056 5090 16908 13677 12634 11435 1425 8647 3876 10694 12256 3853 19901 5723 11065 6147 13613 13768 15794 14993 5819 8117 13871 14708 15099 7152 9810 14438 10557 3209 1265 13915...
output:
...
result:
wrong answer 554th words differ - expected: '864711265', found: '826457499'