# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
944920 |
2024-03-13T08:05:01 Z |
siewjh |
Triple Jump (JOI19_jumps) |
C++17 |
|
4000 ms |
39760 KB |
#include <bits/stdc++.h>
using namespace std;
struct node{
int s, e, m, val;
node *l, *r;
node (int _s, int _e){
s = _s, e = _e, m = (s + e) >> 1, val = 0;
if (s != e){
l = new node(s, m);
r = new node(m + 1, e);
}
}
void update(int p, int v){
val = max(val, v);
if (s == e) return;
else if (p <= m) l->update(p, v);
else r->update(p, v);
}
int query(int x, int y){
if (x == s && y == e) return val;
else if (y <= m) return l->query(x, y);
else if (x > m) return r->query(x, y);
else return max(l->query(x, m), r->query(m + 1, y));
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int nums; cin >> nums;
vector<int> vec(nums + 1);
for (int i = 1; i <= nums; i++) cin >> vec[i];
int queries; cin >> queries;
vector<tuple<int, int, int>> qvec(queries);
for (int i = 0; i < queries; i++){
int l, r; cin >> l >> r;
qvec[i] = {r, l, i};
}
sort(qvec.begin(), qvec.end());
vector<int> ans(queries);
node *root = new node(1, nums), *rootmx = new node(1, nums);
for (int i = 1; i <= nums; i++) rootmx->update(i, vec[i]);
int curr = 2;
for (auto [r, l, qind] : qvec){
while (curr <= r){
curr++;
for (int i = curr - 2; i >= 1; i--) root->update(i, vec[i] + rootmx->query(i + 1, (i + curr) >> 1) + vec[curr]);
}
ans[qind] = root->query(l, r);
}
for (int x : ans) cout << x << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4026 ms |
39760 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |