Submission #970485

#TimeUsernameProblemLanguageResultExecution timeMemory
970485DAleksaTriple Jump (JOI19_jumps)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define int long long struct query { int l, r; int ans; }; struct node { int mx; int ans; int lzy; }; const int N = 5e5 + 10; int n, q; int a[N]; query Q[N]; node st[4 * N]; vector<int> qs[N]; vector<int> upd[N]; stack<int> stk; void build(int index, int l, int r) { if(l > r) return; if(l == r) { st[index].mx = a[l]; st[index].ans = 0; st[index].lzy = 0; return; } int mid = (l + r) / 2; build(2 * index, l, mid); build(2 * index + 1, mid + 1, r); st[index].mx = max(st[2 * index].mx, st[2 * index + 1].mx); } void propagate(int index) { if(2 * index + 1 < 4 * N && st[index].lzy > 0) { st[2 * index].ans = max(st[2 * index].ans, st[2 * index].mx + st[index].lzy); st[2 * index].lzy = max(st[2 * index].lzy, st[index].lzy); st[2 * index + 1].ans = max(st[2 * index + 1].ans, st[2 * index + 1].mx + st[index].lzy); st[2 * index + 1].lzy = max(st[2 * index + 1].lzy, st[index].lzy); st[index].lzy = 0; } } void update(int index, int l, int r, int L, int R, int val) { if(l > r || r < L || R < l) return; if(L <= l && r <= R) { st[index].ans = max(st[index].ans, val + st[index].mx); st[index].lzy = max(st[index].lzy, val); return; } propagate(index); int mid = (l + r) / 2; update(2 * index, l, mid, L, R, val); update(2 * index + 1, mid + 1, r, L, R, val); st[index].ans = max({t[2 * index].ans, st[2 * index + 1].ans, st[index].mx + val}); } int get(int index, int l, int r, int L, int R) { if(l > r || r < L || R < l) return 0; if(L <= l && r <= R) return st[index].ans; propagate(index); int mid = (l + r) / 2; return max(get(2 * index, l, mid, L, R), get(2 * index + 1, mid + 1, r, L, R)); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; cin >> q; for(int i = 1; i <= q; i++) { cin >> Q[i].l >> Q[i].r; qs[Q[i].l].push_back(i); } for(int i = 1; i <= n; i++) { while(!stk.empty() && a[stk.top()] <= a[i]) stk.pop(); if(!stk.empty()) { int x = stk.top(), y = i; if(y + (y - x) <= n) upd[x].push_back(y); } stk.push(i); } while(!stk.empty()) stk.pop(); for(int i = n; i >= 1; i--) { while(!stk.empty() && a[stk.top()] <= a[i]) stk.pop(); if(!stk.empty()) { int x = i, y = stk.top(); if(y + (y - x) <= n) upd[x].push_back(y); } stk.push(i); } build(1, 1, n); for(int l = n; l >= 1; l--) { for(int y : upd[l]) { int x = l; int z = y + (y - x); update(1, 1, n, z, n, a[x] + a[y]); } for(int ind : qs[l]) { int r = Q[ind].r; Q[ind].ans = get(1, 1, n, l, r); } } for(int i = 1; i <= q; i++) cout << Q[i].ans << "\n"; return 0; }

Compilation message (stderr)

jumps.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int, long long int)':
jumps.cpp:62:26: error: 't' was not declared in this scope
   62 |     st[index].ans = max({t[2 * index].ans, st[2 * index + 1].ans, st[index].mx + val});
      |                          ^
jumps.cpp:62:86: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   62 |     st[index].ans = max({t[2 * index].ans, st[2 * index + 1].ans, st[index].mx + val});
      |                                                                                      ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from jumps.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
jumps.cpp:62:86: note:   candidate expects 2 arguments, 1 provided
   62 |     st[index].ans = max({t[2 * index].ans, st[2 * index + 1].ans, st[index].mx + val});
      |                                                                                      ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from jumps.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
jumps.cpp:62:86: note:   candidate expects 3 arguments, 1 provided
   62 |     st[index].ans = max({t[2 * index].ans, st[2 * index + 1].ans, st[index].mx + val});
      |                                                                                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from jumps.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed: