Submission #806866

#TimeUsernameProblemLanguageResultExecution timeMemory
806866hugo_pmTriple Jump (JOI19_jumps)C++17
5 / 100
4043 ms37316 KiB
#include <bits/stdc++.h> #define int long long using namespace std; #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define rep(i, a, b) for(int i = (a); i < (b); i++) #define sz(v) ((int)((v).size())) template<typename T> void chmax(T &x, const T &v) { if (x < v) x = v; } template<typename T> void chmin(T &x, const T &v) { if (x > v) x = v; } using pii = pair<int, int>; using vi = vector<int>; string to_string(string s) { return s; } template <typename T> string to_string(T v) { bool first = true; string res = "["; for (const auto &x : v) { if (!first) res += ", "; first = false; res += to_string(x); } res += "]"; return res; } template <typename val, typename B> string to_string(pair<val, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void dbg_out() { cout << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << to_string(H); dbg_out(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif struct Segtree { #define op max const int e = -1e18; vector<int> tree; int N; Segtree(vector<int> v) { N = v.size(); tree.resize(2*N); for (int i = 2*N-1; i >= 1; --i) { tree[i] = (i >= N ? v[i-N] : op(tree[2*i], tree[2*i+1])); } } int query_include(int L, int R) { L += N, R += N+1; int res = e; while (L < R) { if (L & 1) res = op(res, tree[L++]); if (R & 1) res = op(res, tree[--R]); L /= 2, R /= 2; } return res; } #undef op }; struct Req { int l, r, i; }; signed main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<int> val(N); for (int &x : val) cin >>x; int Q; cin >> Q; vector<vector<Req>> req(N); vector<int> ansReq(Q); rep(i, 0, Q) { int l, r; cin >> l >> r; --l, --r; req[l].push_back({l, r, i}); } vector<int> stk; vector<vi> cand(N); rep(B, 0, N) { while (!stk.empty()) { int A = stk.back(); cand[A].push_back(B); if (val[A] >= val[B]) break; stk.pop_back(); } stk.push_back(B); } Segtree st(val); vector<pii> ptRouge, ptBleu; for (int i = N-1; i >= 0; --i) { ptBleu.emplace_back(i, val[i]); { int A = i; for (int B : cand[i]) { int suffC = B + (B-A); ptRouge.emplace_back(suffC, val[A]+val[B]); } } for (Req rq : req[i]) { for (auto [xR, yR] : ptRouge) for (auto [xB, yB] : ptBleu) { if (xR <= xB && xB <= rq.r) chmax(ansReq[rq.i], yR+yB); } } } rep(i, 0, Q) { cout << ansReq[i] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...