QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#351360 | #7899. Say Hello to the Future | oscaryang | WA | 322ms | 54332kb | C++20 | 3.7kb | 2024-03-11 21:02:29 | 2024-03-11 21:02:30 |
Judging History
answer
#include<bits/stdc++.h>
#define vc vector
#define pb emplace_back
#define pii pair<int, int>
#define mkp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define lep(i, a, b) for(int i = (a); i >= (b); --i)
using namespace std;
inline int read() {
int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x;
}
const int N = 2e5 + 5, LOG = 20, P = 998244353;
inline void inc(int &x, int y) { x += y - P; x += (x >> 31) & P; }
inline void dec(int &x, int y) { x -= y; x += (x >> 31) & P; }
inline int pls(int x, int y) { x += y - P; x += (x >> 31) & P; return x; }
namespace sgt {
int lc[N * LOG], rc[N * LOG], tre[N * LOG], rt[N], idx;
#define mid (l + r >> 1)
inline int newnode() { ++idx; lc[idx] = rc[idx] = tre[idx] = 0; return idx; }
inline void ins(int &k, int pr, int l, int r, int p, int v) {
k = newnode(); lc[k] = lc[pr]; rc[k] = rc[pr]; inc(tre[k] = tre[pr], v);
if(l != r) return p <= mid ? ins(lc[k], lc[pr], l, mid, p, v) : ins(rc[k], rc[pr], mid + 1, r, p, v);
}
inline int ask(int k, int l, int r, int L, int R) {
if(!k || L > R || l > R || r < L) return 0;
if(L <= l && R >= r) return tre[k];
return pls(ask(lc[k], l, mid, L, R), ask(rc[k], mid + 1, r, L, R));
}
}
using namespace sgt;
int n, a[N], b[N], f[N], g[N], dp[N];
inline void solvef(int l, int r) {
if(l == r) return ;
solvef(l, mid);
rep(i, l, r) rt[i] = b[i] = 0; idx = 0;
lep(i, mid - 1, l) b[i] = max(b[i + 1], a[i + 1]);
rep(i, mid + 1, r) b[i] = max(b[i - 1], a[i]);
rep(i, l, mid) {
rt[i] = i > l ? rt[i - 1] : 0;
if(i + b[i] <= r) ins(rt[i], rt[i], 0, n, i + b[i], f[i]);
}
rep(i, mid + 1, r)
if(i - b[i] >= l) inc(f[i], ask(rt[min(mid, i - b[i])], 0, n, 0, i));
solvef(mid + 1, r);
}
inline void solveg(int l, int r) {
if(l == r) return ;
solveg(mid + 1, r);
rep(i, l, r) rt[i] = b[i] = 0; idx = 0;
lep(i, mid - 1, l) b[i] = max(b[i + 1], a[i + 1]);
rep(i, mid + 1, r) b[i] = max(b[i - 1], a[i]);
lep(i, r, mid + 1) {
rt[i] = i < r ? rt[i + 1] : 0;
if(i - b[i] >= l) ins(rt[i], rt[i], 0, n, i - b[i], g[i]);
}
lep(i, mid, l)
if(i + b[i] <= r) inc(g[i], ask(rt[max(mid + 1, i + b[i])], 0, n, i, n));
solveg(l, mid);
}
inline void solvedp(int l, int r) {
if(l == r) return ;
solvedp(l, mid); solvedp(mid + 1, r);
rep(i, l, r) rt[i] = b[i] = 0; idx = 0;
lep(i, mid - 1, l) b[i] = max(b[i + 1], a[i + 1]);
rep(i, mid + 1, r) b[i] = max(b[i - 1], a[i]);
rep(i, l, mid) {
rt[i] = i > l ? rt[i - 1] : 0;
if(i + b[i] <= r) ins(rt[i], rt[i], 0, n, i + b[i], f[i]);
}
lep(i, r, mid + 1) {
rt[i] = i < r ? rt[i + 1] : 0;
if(i - b[i] >= l) ins(rt[i], rt[i], 0, n, i - b[i], g[i]);
}
for(int i = mid + 1, mx = 0, val = 0, j; i <= r; i++) {
if(a[i] > mx) val = mx, mx = a[i], j = i;
val = max(val, i == j ? 1 : a[i]);
if(i - b[i] >= l) dec(dp[j], ask(rt[min(mid, i - b[i])], 0, n, 0, i) * g[i] % P);
if(i - val >= l) inc(dp[j], ask(rt[min(mid, i - val)] , 0, n, 0, i) * g[i] % P);
}
for(int i = mid, mx = 0, val = 0, j = 0; i >= l; i--) {
if(j && i + b[i] <= r) dec(dp[j], ask(rt[max(mid + 1, i + b[i])], 0, n, i, n) * f[i] % P);
if(j && i - val <= r) inc(dp[j], ask(rt[max(mid + 1, i + val)] , 0, n, i, n) * f[i] % P);
if(a[i] > mx) val = mx, mx = a[i], j = i;
val = max(val, i == j ? 1 : a[i]);
}
}
signed main() {
n = read();
rep(i, 1, n) a[i] = read();
f[0] = 1; solvef(0, n);
g[n] = 1; solveg(0, n);
// rep(i, 0, n) cerr << i << " " << f[i] << " " << g[i] << endl;
solvedp(0, n);
rep(i, 1, n) printf("%d%c", f[n] + dp[i], " \n"[i == n]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 14084kb
input:
5 1 3 2 1 2
output:
3 6 3 3 6
result:
ok 5 tokens
Test #2:
score: -100
Wrong Answer
time: 322ms
memory: 54332kb
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:
1231047774 826457499 826457499 826457499 826457499 1307505264 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 82645749...
result:
wrong answer 1st words differ - expected: '157122482', found: '1231047774'