이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
 
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
void setIO() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  if (fopen("input.inp", "r")) {
    freopen("input.inp", "r", stdin);
    freopen("input.out", "w", stdout);
  }
}
const int N = 5e5+5;
int n, q, a[N], ans[N];
// segment tree
int nax[N << 2], cand[N << 2], lazy[N << 2];
void apply(int id) { 
  if (lazy[id] == 0) return;
  int k = id << 1;
  
  lazy[k] = max(lazy[k], lazy[id]);
  cand[k] = max(cand[k], nax[k] + lazy[k]);
  lazy[k+1] = max(lazy[k+1], lazy[id]);
  cand[k+1] = max(cand[k+1], nax[k+1] + lazy[k+1]);
  lazy[id] = 0;
}
void build(int id = 1, int lb = 1, int rb = n) {
  if (lb ^ rb) {
    int k = id << 1, mb = (lb + rb) >> 1;
    build(k, lb, mb);
    build(k+1, mb+1, rb);
    nax[id] = max(nax[k], nax[k+1]);
  }
  else {
    nax[id] = a[lb];
  }
}
void update(int l, int v, int id = 1, int lb = 1, int rb = n) {
  if (l <= lb) {
    lazy[id] = max(lazy[id], v);
    cand[id] = max(cand[id], v + nax[id]);
    return;
  }
  else if (rb < l) {
    return;
  }
  int k = id << 1, mb = (lb + rb) >> 1;
  apply(id);
  update(l, v, k, lb, mb);
  update(l, v, k+1, mb+1, rb);
  cand[id] = max(cand[k], cand[k+1]);
}
int question(int l, int r, int id = 1, int lb = 1, int rb = n) {
  if (l <= lb && rb <= r) {
    return cand[id];
  }
  else if (rb < l || lb > r) {
    return 0;
  }
  int k = id << 1, mb = (lb + rb) >> 1;
  apply(id);
  return max(question(l, r, k, lb, mb), question(l, r, k+1, mb+1, rb));
}
// querys
vector<pair<ii, int>> querys;
int main() {
  setIO();
  cin >> n;
  foru(i, 1, n) cin >> a[i];
  build();
  cin >> q;
  foru(i, 1, q) {
    int l, r;
    cin >> l >> r;
    querys.push_back({{l, r}, i});
  }
  sort(all(querys), greater<pair<ii, int>>());
  stack<int> st;
  int j = 0;
  ford(i, n, 1) {
    while (!st.empty()) {
      int j = st.top();
      if (2*j-i <= n) {
        // cout << "upd " << i << " " << j << " at " << 2*j-i << " value "  << a[i] + a[j] << "\n";
        update(2*j-i, a[i] + a[j]);
      }
      if (a[j] <= a[i]) st.pop();
      else break;
    }
    st.push(i);
    while (j < q && querys[j].first.first == i) {
      auto ask = querys[j];
      int l = ask.first.first, r = ask.first.second, id = ask.second;
      ans[id] = question(l, r);
      // cout << "ques " << l << " " << r << " " << ans[id] << "\n";
      ++j;
    }
  }
  foru(i, 1, q) {
    cout << ans[i] << "\n";
  }
} 
컴파일 시 표준 에러 (stderr) 메시지
jumps.cpp: In function 'void setIO()':
jumps.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen("input.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen("input.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |