# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1096373 |
2024-10-04T11:07:30 Z |
ducdev |
Triple Jump (JOI19_jumps) |
C++14 |
|
191 ms |
524288 KB |
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int MAX_N = 1e6;
const int MOD = 1e9 + 7;
struct SegmentTree {
vector<ll> seg, lazy;
int n;
void down(int node) {
if (lazy[node] == 0) return;
for (int i = 0; i < 2; i++) {
seg[node << 1 | i] = max(seg[node << 1 | i], lazy[node]);
lazy[node << 1 | i] = max(seg[node << 1 | i], lazy[node]);
};
lazy[node] = 0;
};
void update(int node, int l, int r, int u, int v, ll val) {
if (l > v || r < u) return;
if (l >= u && r <= v) {
seg[node] = max(seg[node], val);
lazy[node] = max(lazy[node], val);
return;
};
int mid = (l + r) >> 1;
down(node);
update(node << 1, l, mid, u, v, val);
update(node << 1 | 1, mid + 1, r, u, v, val);
seg[node] = max(seg[node << 1], seg[node << 1 | 1]);
};
ll get(int node, int l, int r, int u, int v) {
if (l > v || r < u) return 0;
if (l >= u && r <= v) return seg[node];
int mid = (l + r) >> 1;
down(node);
return max(get(node << 1, l, mid, u, v), get(node << 1 | 1, mid + 1, r, u, v));
};
void update(int l, int r, ll val) {
update(1, 1, n, l, r, val);
};
int get(int l, int r) {
return get(1, 1, n, l, r);
};
void init(int _n) {
n = _n;
seg.assign(4 * n + 5, 0);
lazy.assign(4 * n + 5, 0);
};
SegmentTree() {};
SegmentTree(int n) : n(n) {
init(n);
};
};
int n;
ll a[MAX_N + 5], ans[5005][5005];
SegmentTree seg[5005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen("MAIN.INP", "r")) {
freopen("MAIN.INP", "r", stdin);
freopen("MAIN.OUT", "w", stdout);
};
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int r = 1; r <= n; r++) seg[r].init(n);
for (int r = 3; r <= n; r++) {
for (int mid = r - 1; mid > 1; mid--) {
int minL = max(1, mid - (r - mid));
seg[r].update(minL, mid - 1, a[r] + a[mid]);
};
};
for (int r = 3; r <= n; r++) {
for (int l = r - 2; l >= 1; l--) {
ans[l][r] = seg[r].get(l, l) + a[l];
ans[l][r] = max(ans[l][r], ans[l + 1][r]);
ans[l][r] = max(ans[l][r], ans[l][r - 1]);
}
}
int q;
for (cin >> q; q--;) {
int l, r;
cin >> l >> r;
cout << ans[l][r] << '\n';
};
};
Compilation message
jumps.cpp: In function 'int main()':
jumps.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen("MAIN.INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen("MAIN.OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
2 ms |
1628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
2 ms |
1628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
191 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
2 ms |
1628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |