QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#327234 | #7899. Say Hello to the Future | yllcm | WA | 677ms | 47700kb | C++14 | 4.8kb | 2024-02-14 20:46:35 | 2024-02-14 20:46:35 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
int x = 0; bool op = false;
char c = getchar();
while(!isdigit(c))op |= (c == '-'), c = getchar();
while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int P = 998244353;
void add(int &a, int b) {a += b; a >= P ? a -= P : 0;}
void sub(int &a, int b) {a -= b; a < 0 ? a += P : 0;}
const int N = 2e5 + 10;
int n;
int a[N], st[N][25];
int cmin(int x, int y) {return a[x] > a[y] ? x : y;}
void build() {
for(int i = 1; i <= n; i++)st[i][0] = i;
for(int j = 1; (1 << j) <= n; j++) {
for(int i = 1; i + (1 << j) - 1 <= n; i++) {
st[i][j] = cmin(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
}
return ;
}
int query(int l, int r) {
int t = __lg(r - l + 1);
return cmin(st[l][t], st[r - (1 << t) + 1][t]);
}
int d[N], f[N], sum[N], g[N];
void solve(int l, int r) {
int k = query(l, r);
if(l < k)solve(l, k - 1);
if(k - l < r - k) {
for(int i = l; i <= k; i++) {
int p = i + a[k] - 1;
if(p <= r)add(d[p], f[i - 1]), sub(d[r + 1], f[i - 1]);
}
}
else {
for(int i = k; i <= r; i++) {
int p = i - a[k] + 1;
if(p >= l)add(f[i], sum[p - 1]), sub(f[i], sum[l - 2]);
}
}
add(d[k], d[k - 1]); add(f[k], d[k]);
sum[k] = (sum[k - 1] + f[k]) % P;
if(k < r)solve(k + 1, r);
return ;
}
struct Mx {int mx, cmx, pos;}mx[N];
int tot;
int id1[N], id2[N], ans[N * 2], d2[N];
struct Qry {int id, mx, len, w;};
struct BIT {
int sum[N];
void update(int x, int w) {
x = max(min(x, n + 1), 1);
for(int i = x; i <= n; add(sum[i], w), i += (i & -i));
return ;
}
int query(int x) {
x = max(min(x, n), 0);
int res = 0;
for(int i = x; i; add(res, sum[i]), i = i & (i - 1));
return res;
}
}T;
void work(vector<Qry> V) {
sort(V.begin(), V.end(), [&](Qry x, Qry y) {return x.mx < y.mx;});
for(auto t : V) {
if(t.id == 0)T.update(n - t.len + 1, t.w);
else add(ans[t.id], 1ll * t.w * T.query(n - (t.mx - t.len) + 1) % P);
}
for(auto t : V)if(t.id == 0)T.update(n - t.len + 1, P - t.w);
reverse(V.begin(), V.end());
for(auto t : V) {
if(t.id == 0)T.update(t.mx - t.len, t.w);
else add(ans[t.id], 1ll * t.w * T.query(t.len) % P);
}
for(auto t : V)if(t.id == 0)T.update(t.mx - t.len, P - t.w);
return ;
}
void cdq(int l, int r) {
if(l == r) {
add(d2[l], 1ll * f[l - 1] * g[l + 1] % P);
return ;
}
int mid = l + r >> 1;
Mx now = {1, 1};
for(int i = mid; i >= l; i--) {
if(a[i] >= now.mx)now.cmx = now.mx, now.mx = a[i], now.pos = i;
else if(a[i] > now.cmx)now.cmx = a[i];
mx[i] = now;
}
now = {1, 1};
for(int i = mid + 1; i <= r; i++) {
if(a[i] >= now.mx)now.cmx = now.mx, now.mx = a[i], now.pos = i;
else if(a[i] > now.cmx)now.cmx = a[i];
mx[i] = now;
}
vector<Qry> V; tot = 0;
for(int i = l; i <= mid; i++) {
id1[i] = ++tot; ans[tot] = 0; V.pb({tot, mx[i].mx, mid - i + 1, f[i - 1]});
id2[i] = ++tot; ans[tot] = 0; V.pb({tot, mx[i].cmx, mid - i + 1, f[i - 1]});
}
for(int i = mid + 1; i <= r; i++)V.pb({0, mx[i].mx, i - mid, g[i + 1]});
work(V);
// printf("solve:%d %d %d\n", l, r, mid);
for(int i = l; i <= mid; i++) {
add(d[i], ans[id1[i]]);
sub(d[mid + 1], ans[id1[i]]);
// printf("contri:%d %d %d\n", i, ans[id1[i]], ans[id2[i]]);
add(d2[mx[i].pos], ans[id2[i]]);
sub(d2[mx[i].pos], ans[id1[i]]);
}
vector<Qry>().swap(V); tot = 0;
for(int i = mid + 1; i <= r; i++) {
id1[i] = ++tot; ans[tot] = 0; V.pb({tot, mx[i].mx, r - mid, g[i + 1]});
id2[i] = ++tot; ans[tot] = 0; V.pb({tot, mx[i].cmx, r - mid, g[i + 1]});
}
for(int i = l; i <= mid; i++)V.pb({0, mx[i].mx, mid - i + 1, f[i - 1]});
work(V);
for(int i = mid + 1; i <= r; i++) {
add(d[mid + 1], ans[id1[i]]);
sub(d[i + 1], ans[id1[i]]);
add(d2[mx[i].pos], ans[id2[i]]);
sub(d2[mx[i].pos], ans[id1[i]]);
}
cdq(l, mid); cdq(mid + 1, r);
return ;
}
int main() {
n = read();
for(int i = 1; i <= n; i++)a[i] = read();
build();
f[0] = sum[0] = 1;
memset(d, 0, sizeof(d));
solve(1, n); swap(f, g);
reverse(a + 1, a + 1 + n);
build();
f[0] = sum[0] = 1;
memset(d, 0, sizeof(d));
solve(1, n); swap(f, g);
reverse(g, g + 2 + n);
reverse(a + 1, a + 1 + n);
memset(d, 0, sizeof(d));
cdq(1, n);
for(int i = 1; i <= n; i++)add(d[i], d[i - 1]);
for(int i = 1; i <= n; i++)printf("%d ", (d[i] + d2[i]) % P);putchar('\n');
// printf("f:"); for(int i = 0; i <= n + 1; i++)printf("%d ", f[i]); putchar('\n');
// printf("g:"); for(int i = 0; i <= n + 1; i++)printf("%d ", g[i]); putchar('\n');
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 14000kb
input:
5 1 3 2 1 2
output:
3 6 3 3 6
result:
ok 5 tokens
Test #2:
score: -100
Wrong Answer
time: 677ms
memory: 47700kb
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:
327696010 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 915971883 ...
result:
wrong answer 1st words differ - expected: '157122482', found: '327696010'