QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#331853 | #7616. Jump Graph | yllcm | WA | 1ms | 7904kb | C++14 | 1.5kb | 2024-02-18 20:33:43 | 2024-02-18 20:33:44 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#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 = 0;
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 N = 3e5 + 10;
int n;
int p[N];
ll f[N], g[N], d[N], st[N][25];
int cmax(int x, int y) {return p[x] > p[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] = cmax(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 cmax(st[l][t], st[r - (1 << t) + 1][t]);
}
int solve(int l, int r) {
int k = query(l, r), ls = 0, rs = 0;
if(l < k)ls = solve(l, k - 1);
if(k < r)rs = solve(k + 1, r);
auto add = [&](int l, int r, int w) {d[l] += w; d[r + 1] -= w;};
f[k] = f[ls] + f[rs] + r - k + 1;
g[k] = g[ls] + g[rs] + k - l + 1;
add(l, k - 1, 1 + r - k + f[rs]);
add(k + 1, r, 1 + k - l + g[ls]);
add(k, k, g[ls] + f[rs]);
return k;
}
int main() {
n = read();
for(int i = 1; i <= n; i++)p[i] = read();
build(); solve(1, n);
for(int i = 1; i <= n; i++)d[i] += d[i - 1];
for(int i = 1; i <= n; i++)printf("%lld ", d[i]); putchar('\n');
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7900kb
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: 1ms
memory: 5880kb
input:
2 1 2
output:
1 1
result:
ok single line: '1 1 '
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 7904kb
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 '