# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
797420 | fatemetmhr | Triple Jump (JOI19_jumps) | C++17 | 307 ms | 87104 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.
// Be name khoda //
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
using namespace std;
const int maxn5 = 5e3 + 10;
const int maxn = 1e6 + 10;
const int lg = 20;
const ll inf = 1e18;
int a[maxn5], rmq[maxn5][maxn5];
ll mx[maxn5], out[maxn];
vector <pair<pair<int, int>, int>> req;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
rmq[i][i] = a[i];
}
for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++)
rmq[i][j] = max(rmq[i][j - 1], a[j]);
int q; cin >> q;
for(int i = 0; i < q; i++){
int l, r; cin >> l >> r;
l--; r--;
req.pb({{r, l}, i});
}
sort(all(req));
int ind = 0;
for(int i = 0; i < n; i++){
for(int j = i - 2; j >= 0; j--)
mx[j] = max({mx[j + 1], mx[j], ll(a[j]) + a[i] + rmq[j + 1][(i + j) / 2]});
while(ind < req.size() && req[ind].fi.fi == i){
out[req[ind].se] = mx[req[ind].fi.se];
ind++;
}
}
for(int i = 0; i < q; i++)
cout << out[i] << '\n';
}
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... |