QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220552 | #7616. Jump Graph | ucup-team2303# | WA | 2ms | 12076kb | C++14 | 1.7kb | 2023-10-20 15:14:55 | 2023-10-20 15:14:55 |
Judging History
answer
// #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define PB emplace_back
#define int long long
#define ll long long
#define vi vector<int>
#define siz(a) ((int) ((a).size()))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
void print(vi n) {rep(i, 0, siz(n) - 1) cerr << n[i] << " \n"[i == siz(n) - 1];}
const int N = 3e5;
int a, s[N + 5], ls[N + 5], rs[N + 5], fa[N + 5], rt, p[N + 5], L[N + 5], R[N + 5],
ans[N + 5], l[N + 5], r[N + 5];
void dfs(int n) {
if(ls[n]) dfs(ls[n]), l[n] = l[ls[n]];
else l[n] = n;
if(rs[n]) dfs(rs[n]), r[n] = r[rs[n]];
else r[n] = n;
}
void Dfs(int n) {
if(ls[n]) Dfs(ls[n]);
if(rs[n]) Dfs(rs[n]);
L[n] = 1 + L[rs[n]] + r[n] - n + L[ls[n]];
R[n] = 1 + R[ls[n]] + n - l[n] + R[rs[n]];
ans[n] = L[rs[n]] + R[ls[n]];
}
void calc(int n, int w) {
ans[n] += w;
if(ls[n]) calc(ls[n], w + 1 + L[rs[n]] + r[n] - n);
if(rs[n]) calc(rs[n], w + 1 + R[ls[n]] + n - l[n]);
}
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> a;
rep(i, 1, a) {
cin >> s[i];
int now = i - 1;
while(now && s[now] < s[i]) now = fa[now];
if(!now) ls[i] = rt, fa[rt] = i, rt = i;
else {
ls[i] = rs[now];
fa[rs[now]] = i;
rs[now] = i;
fa[i] = now;
}
}
dfs(rt);
Dfs(rt);
// cout << L[5] << endl;
calc(rt, 0);
rep(i, 1, a) cout << ans[i] << ' ';
return cerr << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl, 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11956kb
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: 2ms
memory: 11960kb
input:
2 1 2
output:
1 1
result:
ok single line: '1 1 '
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 12076kb
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 '