QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#223071 | #7616. Jump Graph | ucup-team296# | WA | 0ms | 3852kb | C++14 | 2.5kb | 2023-10-21 21:15:25 | 2023-10-21 21:15:25 |
Judging History
answer
#include <bits/stdc++.h>
#define long long long int
#define DEBUG
using namespace std;
// @author: pashka
struct segtree {
typedef pair<int, int> item;
item zero_sum = {INT_MIN, -1};
item oper(item a, item b) {
return max(a, b);
}
vector<item> sums;
int size;
void set(int i, item x, int n, int L, int R) {
if (R == L + 1) {
sums[n] = x;
return;
}
int M = (L + R) >> 1;
if (i < M) {
set(i, x, 2 * n + 1, L, M);
} else {
set(i, x, 2 * n + 2, M, R);
}
sums[n] = oper(sums[2 * n + 1], sums[2 * n + 2]);
}
item calc(int l, int r, int n, int L, int R) {
if (l >= R || L >= r) return zero_sum;
if (L >= l && R <= r) {
return sums[n];
}
int M = (L + R) >> 1;
return oper(calc(l, r, 2 * n + 1, L, M),
calc(l, r, 2 * n + 2, M, R));
}
explicit segtree(int n) {
size = 1;
while (size < n) size *= 2;
sums.assign(2 * size, zero_sum);
}
explicit segtree(vector<item> a): segtree(a.size()) {
int n = a.size();
for (int i = 0; i < n; i++) {
sums[size - 1 + i] = a[i];
}
for (int i = size - 2; i >= 0; i--) {
sums[i] = oper(sums[2 * i + 1], sums[2 * i + 2]);
}
}
void set(int i, item x) {
set(i, x, 0, 0, size);
}
item calc(int l, int r) {
return calc(l, r, 0, 0, size);
}
};
vector<long> res;
void add_res(int l, int r, long x) {
res[l] += x;
res[r] -= x;
}
pair<long, long> go(int l, int r, segtree &st) {
if (r == l) return {0, 0};
int x = st.calc(l, r).second;
auto ll = go(l, x, st);
auto rr = go(x + 1, r, st);
add_res(x, x + 1, ll.second + rr.first);
add_res(l, x, 1 + rr.first + (r - x - 1));
add_res(x + 1, r, 1 + ll.second + (x - l));
return {ll.first + 1 + rr.first + (r - x - 1),
rr.second + 1 + ll.second + (x - l)};
}
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<pair<int, int>> p(n);
for (int i = 0; i < n; i++) {
cin >> p[i].first;
p[i].second = i;
}
segtree st(p);
res.resize(n + 1);
go(0, n, st);
for (int i = 1; i <= n; i++) res[i] += res[i - 1];
for (int i = 0; i< n; i++) cout << res[i] << " ";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
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: 3620kb
input:
2 1 2
output:
1 1
result:
ok single line: '1 1 '
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
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 '