Submission #967568

#TimeUsernameProblemLanguageResultExecution timeMemory
967568Neco_arcTriple Jump (JOI19_jumps)C++17
100 / 100
857 ms73752 KiB
#include <bits/stdc++.h> #define ll long long #define all(x) x.begin(), x.end() #define Neco "Triple Jump" #define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) #define getbit(x,i) ((x >> i)&1) #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define cntbit(x) __builtin_popcountll(x) #define fi(i, a, b) for(int i = a; i <= b; i++) #define fid(i, a, b) for(int i = a; i >= b; i--) #define maxn (int) 5e5 + 7 using namespace std; const ll mod = 1e9 + 7; //972663749 const ll base = 911382323; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll GetRandom(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rng); } int n, Q; int q[maxn], top; struct dl { int l, r, id; } qr[maxn]; vector<pair<int, int>> P; ll a[maxn], nex[2 * maxn], ans[maxn]; struct IT { struct Node { ll Le, Ri, All; } st[4 * maxn]; Node cb(Node x, Node y) { Node P; P.Le = max(x.Le, y.Le); P.Ri = max(x.Ri, y.Ri); P.All = max({x.All, y.All, x.Le + y.Ri}); return P; } void update(int x, int val, int id = 1, int l = 1, int r = n) { if(l > x || r < x) return ; if(l == r) { st[id].Le = val, st[id].Ri = a[l]; st[id].All = st[id].Le + st[id].Ri; return ; } int mid = (l + r) >> 1; update(x, val, _left), update(x, val, _right); st[id] = cb(st[id * 2], st[id * 2 + 1]); } Node get(int u, int v, int id = 1, int l = 1, int r = n) { if(l > v || r < u) return {0, 0, 0}; if(u <= l && r <= v) return st[id]; int mid = (l + r) >> 1; return cb(get(u, v, _left), get(u, v, _right)); } } St; void solve() { cin >> n ; fi(i, 1, n) cin >> a[i]; cin >> Q; fi(i, 1, Q) cin >> qr[i].l >> qr[i].r, qr[i].id = i; // fi(i, 1, n) { while(top && a[i] >= a[q[top]]) P.push_back({q[top], i}), --top; if(top) P.push_back({q[top], i}); q[++top] = i; } sort(all(P), [](pair<int, int> x, pair<int, int> y) { return x.first < y.first; } ); for(int i = P.size() - 1; i >= 0; -- i) { int u, v, id, val; tie(u, v) = P[i]; id = v * 2 - u, val = St.get(id, id).Le; nex[i] = val, St.update(id, max(1ll * val, a[u] + a[v])); } sort(qr + 1, qr + 1 + Q, [](dl x, dl y) { return x.l < y.l; } ); int j = 0; fi(i, 1, Q) { while(P[j].first < qr[i].l) { St.update(2 * P[j].second - P[j].first, nex[j]); ++j; } ans[qr[i].id] = St.get(qr[i].l, qr[i].r).All; } fi(i, 1, Q) cout << ans[i] << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(Neco".inp", "r")) { freopen(Neco".inp", "r", stdin); freopen(Neco".out", "w", stdout); } int nTest = 1; // cin >> nTest; while(nTest--) { solve(); } return 0; }

Compilation message (stderr)

jumps.cpp: In function 'void solve()':
jumps.cpp:84:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   84 |         if(top) P.push_back({q[top], i}); q[++top] = i;
      |         ^~
jumps.cpp:84:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   84 |         if(top) P.push_back({q[top], i}); q[++top] = i;
      |                                           ^
jumps.cpp: In function 'int main()':
jumps.cpp:122:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:123:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...