제출 #147246

#제출 시각아이디문제언어결과실행 시간메모리
147246Alexa20013단 점프 (JOI19_jumps)C++17
5 / 100
4026 ms8184 KiB
#include <bits/stdc++.h> using namespace std; const int Nmax = 2e5 + 5; const int inf = 1e9; vector<pair<int,int>> v; int a[Nmax], st[Nmax]; int n, L[Nmax], R[Nmax]; void fnd() { int i, nr = 0; st[0] = 0; a[0] = inf; for(i=1; i<=n; ++i) { while(a[st[nr]] <= a[i]) { v.push_back({st[nr], i}); --nr; } v.push_back({st[nr], i}); st[++nr] = i; } } int best(int x, int y) { int i; int ans = 0; for(i=x; i<=y; ++i) ans = max(ans, a[i]); return ans; } int main() { // freopen("triple.in", "r", stdin); cin.tie(0); cin.sync_with_stdio(false); cin >> n; int i, q; for(i=1; i<=n; ++i) cin >> a[i]; cin >> q; for(i=1; i<=q; ++i) cin >> L[i] >> R[i]; fnd(); for(i=1; i<=q; ++i) { int ans = 0; for(auto el : v) { int x, y, z; tie(x, y) = el; z = 2 * y - x; if(x < L[i] || z > R[i]) continue; ans = max(ans, a[x] + a[y] + best(z, R[i])); } cout << ans << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...