QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#303161 | #7899. Say Hello to the Future | ucup-team173 | WA | 482ms | 25064kb | C++20 | 5.3kb | 2024-01-11 19:53:08 | 2024-01-11 19:53:08 |
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;
}
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];
}
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++;
int x, val;
if(posL[i] == i) x = i, val = max(mxL[i + 1], 1);
else x = posL[i], val = max(smxL[i], 1);
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]);
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++;
int x, val;
if(posR[i] == i) x = i, val = max(mxR[i - 1], 1);
else x = posR[i], val = max(smxR[i], 1);
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]);
}
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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 20000kb
input:
5 1 3 2 1 2
output:
3 6 3 3 6
result:
ok 5 tokens
Test #2:
score: -100
Wrong Answer
time: 482ms
memory: 25064kb
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:
157122482 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 ...
result:
wrong answer 554th words differ - expected: '864711265', found: '826457499'