# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1103936 | ntmin | Triple Jump (JOI19_jumps) | C++14 | 279 ms | 116260 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define ON(a, b) (a >> b & 1)
#define all(x) x.begin(), x.end()
template<typename T> bool maximise(T &a, T b){if(a < b){a = b; return 1;} return 0;}
template<typename T> bool minimise(T &a, T b){if(a > b){a = b; return 1;} return 0;}
const int N = 5e5 + 1;
int a[N], n, q;
pii st[19][N];
const int M = 5010;
int maxx[M][M];
void sub1(){
auto getmax = [&](int l, int r) -> int {
int k = __lg(r - l + 1);
return max(st[k][l].first, st[k][r - (1 << k) + 1].first);
};
for(int i = 1; i <= n; ++i){
for(int j = i + 2; j <= n; ++j){
maxx[i][j] = a[i] + a[j] + getmax(i + 1, i + ((j - i + 1) / 2 - ((j - i + 1) % 2 == 0)));
}
}
for(int i = n; i >= 1; --i){
for(int j = i + 1; j <= n; ++j){
maximise(maxx[i][j], max({maxx[i + 1][j], maxx[i][j - 1], maxx[i + 1][j - 1]}));
}
}
int q; cin >> q;
while(q--){
int l, r; cin >> l >> r;
cout << maxx[l][r] << '\n';
}
}
void sub2(){
priority_queue<pair<int, int>> q;
for(int i = 1; i <= n; ++i){
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen("tjump.INP", "r")){
freopen("tjump.INP", "r", stdin);
freopen("tjump.OUT", "w", stdout);
}
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> a[i];
st[0][i] = {a[i], i};
}
for(int k = 1; k < 19; ++k){
for(int i = 1; i + (1 << k) - 1 <= n; ++i){
st[k][i] = max(st[k - 1][i], st[k - 1][i + (1 << (k - 1))]);
}
}
if(n <= 5000) sub1();
else sub2();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |