#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int oo = 1e9;
int n, a[200001], b[200001], h[200001], ans[200001];
vector<int> ins[400001], rem[400001];
int segtree[800001];
void build(int node = 1, int l = 1, int r = n) {
segtree[node] = -oo;
if (l != r) {
int mid = (l + r) / 2;
build(node * 2, l, mid); build(node * 2 + 1, mid + 1, r);
}
}
void update(int pos, int val, int node = 1, int l = 1, int r = n) {
if (l == r) segtree[node] = val;
else {
int mid = (l + r) / 2;
if (pos > mid) update(pos, val, node * 2 + 1, mid + 1, r);
else update(pos, val, node * 2, l, mid);
segtree[node] = max(segtree[node * 2], segtree[node * 2 + 1]);
}
}
int query(int x, int y, int node = 1, int l = 1, int r = n) {
if (l > y || r < x) return -oo;
if (l >= x && r <= y) return segtree[node];
int mid = (l + r) / 2;
return max(query(x, y, node * 2, l, mid), query(x, y, node * 2 + 1, mid + 1, r));
}
void solve() {
build();
for (int i = 1; i <= n; i++) {
for (int j : ins[i]) update(j, h[j]);
ans[i] = max(ans[i], query(i - b[i], i - a[i]) - h[i]);
for (int j : rem[i]) update(j, -oo);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i] >> a[i] >> b[i];
ins[i + a[i]].push_back(i);
rem[i + b[i]].push_back(i);
}
int q;
cin >> q;
// for (int i = 1; i <= q; i++) {
// cin >> queries[i].first.first >> queries[i].first.second;
// }
if (q == 1) {
memset(ans, -1, sizeof ans);
solve();
for (int i = 1; i <= n; i++) h[i] *= -1;
solve();
cout << *max_element(ans + 1, ans + n + 1);
} else {
cout << "TODO :(";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
19200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
19200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
362 ms |
32376 KB |
Output is correct |
2 |
Correct |
359 ms |
33400 KB |
Output is correct |
3 |
Correct |
275 ms |
29944 KB |
Output is correct |
4 |
Correct |
404 ms |
33448 KB |
Output is correct |
5 |
Correct |
153 ms |
26360 KB |
Output is correct |
6 |
Correct |
371 ms |
33336 KB |
Output is correct |
7 |
Correct |
290 ms |
31864 KB |
Output is correct |
8 |
Correct |
344 ms |
33400 KB |
Output is correct |
9 |
Correct |
51 ms |
22016 KB |
Output is correct |
10 |
Correct |
337 ms |
33300 KB |
Output is correct |
11 |
Correct |
206 ms |
28024 KB |
Output is correct |
12 |
Correct |
340 ms |
33400 KB |
Output is correct |
13 |
Correct |
231 ms |
30044 KB |
Output is correct |
14 |
Correct |
222 ms |
29344 KB |
Output is correct |
15 |
Correct |
213 ms |
30072 KB |
Output is correct |
16 |
Correct |
194 ms |
30768 KB |
Output is correct |
17 |
Correct |
239 ms |
29684 KB |
Output is correct |
18 |
Correct |
212 ms |
29560 KB |
Output is correct |
19 |
Correct |
224 ms |
29616 KB |
Output is correct |
20 |
Correct |
217 ms |
29636 KB |
Output is correct |
21 |
Correct |
226 ms |
29664 KB |
Output is correct |
22 |
Correct |
226 ms |
29936 KB |
Output is correct |
23 |
Correct |
226 ms |
29640 KB |
Output is correct |
24 |
Correct |
197 ms |
30324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
19200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |