QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#234203 | #7616. Jump Graph | zlt | WA | 2ms | 20580kb | C++14 | 1.6kb | 2023-11-01 14:48:25 | 2023-11-01 14:48:26 |
Judging History
answer
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 300100;
int n, a[maxn], b[maxn], stk[maxn], top, L[maxn], R[maxn];
ll f[maxn], g[maxn], sz[maxn];
vector<int> G[maxn];
void dfs(int u) {
sz[u] = 1;
for (int v : G[u]) {
dfs(v);
sz[u] += sz[v];
}
}
void dfs2(int u) {
for (int v : G[u]) {
dfs2(v);
sz[u] += sz[v];
}
}
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
b[a[i]] = i;
}
for (int i = 1; i <= n; ++i) {
while (top && a[stk[top]] < a[i]) {
--top;
}
L[i] = (top ? stk[top] : 1);
stk[++top] = i;
}
top = 0;
for (int i = n; i; --i) {
while (top && a[stk[top]] < a[i]) {
--top;
}
R[i] = (top ? stk[top] : n);
stk[++top] = i;
}
for (int i = 2; i <= n; ++i) {
G[L[i]].pb(i);
}
dfs(1);
dfs2(1);
for (int i = 1; i <= n; ++i) {
f[L[i]] += sz[i];
f[i] -= sz[i];
}
for (int i = 1; i <= n; ++i) {
f[i] += f[i - 1];
vector<int>().swap(G[i]);
}
for (int i = 1; i < n; ++i) {
G[R[i]].pb(i);
}
dfs(n);
dfs2(n);
for (int i = 1; i <= n; ++i) {
g[R[i]] += sz[i];
g[i] -= sz[i];
}
for (int i = n; i; --i) {
g[i] += g[i + 1];
}
for (int i = 1; i <= n; ++i) {
printf("%lld ", f[i] + g[i]);
}
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 20320kb
input:
6 1 6 3 2 5 4
output:
11 7 7 7 6 8
result:
ok single line: '11 7 7 7 6 8 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 20416kb
input:
2 1 2
output:
1 1
result:
ok single line: '1 1 '
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 20580kb
input:
36 9 29 1 3 14 31 24 21 10 18 22 16 8 7 15 12 17 19 25 28 27 34 11 6 32 4 20 13 2 35 23 26 33 36 30 5
output:
101 98 99 99 100 87 81 79 79 79 73 72 71 71 70 72 72 77 83 94 107 100 120 120 116 118 116 116 116 113 142 142 143 143 175 175
result:
wrong answer 1st lines differ - expected: '92 89 90 90 91 78 73 71 71 71 ...110 107 136 136 137 136 168 168', found: '101 98 99 99 100 87 81 79 79 7...16 113 142 142 143 143 175 175 '