Submission #915200

#TimeUsernameProblemLanguageResultExecution timeMemory
915200qinTriple Jump (JOI19_jumps)C++17
27 / 100
64 ms6088 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ssize(x) int(x.size()) #define pn printf("\n") #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define vv vector using namespace std; typedef long long ll; typedef pair<int, int> pii; int inf = 2e09; ll infll = 2e18; int mod = 119<<23|1; struct seg{ vector<int> t; int base = 1; void init(int n, vector<int> &a){ while(base < n) base <<= 1; t.resize(base<<1); for(int i = 1; i <= n; ++i) t[i+base-1] = a[i]; for(int i = base-1; i; --i) t[i] = max(t[i<<1], t[i<<1|1]); } int query_max(int i, int s, int e, int x, int y){ if(x <= s && e <= y) return t[i]; int mid = (s+e)>>1, ret = 0; if(x <= mid) ret = max(ret, query_max(i<<1, s, mid, x, y)); if(mid < y) ret = max(ret, query_max(i<<1|1, mid+1, e, x, y)); return ret; } int query(int x, int y){ if(x <= y) return query_max(1, 1, base, max(1, x), min(base, y)); return 0; } }; void answer(){ int n; scanf("%d", &n); vector<int> t(n+1); for(int i = 1; i <= n; ++i) scanf("%d", &t[i]); seg seg; seg.init(n, t); int q; scanf("%d", &q); for(++q; --q; ){ int l, r; scanf("%d%d", &l, &r); vector<int> st; for(int i = r; i > l; --i) if(st.empty() || t[st.back()] < t[i]) st.emplace_back(i); int mx_pos = l, result = 0; for(int i = l+1; i <= r-1; ++i){ if(st.back() == i) st.pop_back(); result = max(result, seg.query(i-(st.back()-i), i-1)+t[i]+t[st.back()]); result = max(result, t[mx_pos]+t[i]+seg.query(i+(i-mx_pos), n)); if(t[mx_pos] <= t[i]) mx_pos = i; } printf("%d\n", result); } } int main(){ int T = 1; for(++T; --T; ) answer(); return 0; }

Compilation message (stderr)

jumps.cpp: In function 'void answer()':
jumps.cpp:35:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   int n; scanf("%d", &n);
      |          ~~~~~^~~~~~~~~~
jumps.cpp:37:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   for(int i = 1; i <= n; ++i) scanf("%d", &t[i]);
      |                               ~~~~~^~~~~~~~~~~~~
jumps.cpp:39:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   int q; scanf("%d", &q);
      |          ~~~~~^~~~~~~~~~
jumps.cpp:41:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     int l, r; scanf("%d%d", &l, &r);
      |               ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...