Submission #485585

#TimeUsernameProblemLanguageResultExecution timeMemory
485585cheissmartBitaro, who Leaps through Time (JOI19_timeleap)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define int ll #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m"; void DBG() { cerr << "]" << _reset << endl; } template<class H, class...T> void DBG(H h, T ...t) { cerr << to_string(h); if(sizeof ...(t)) cerr << ", "; DBG(t...); } #ifdef CHEISSMART #define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define debug(...) #endif const int INF = 1e9 + 7, N = 3e5 + 7; int n, q; struct DS { struct node { int l, r, x, y; ll cost; bool type; //0: only l, r node(int _l = 0, int _r = 0) { l = _l, r = _r; x = y = 0, type = 0, cost = 0; } pair<int, ll> eval(int pos) { ll ans = 0; int pre = pos; pos = max(pos, l), pos = min(pos, r); ans += max(0, pre - pos); if(type) { ans += cost; pre = pos, pos = x; ans += max(0, pre - pos); pos = y; } return {pos, ans}; } friend node operator + (node lhs, node rhs) { node res; if(lhs.type) { res.l = lhs.l, res.r = lhs.r, res.x = lhs.x, res.type = 1; auto [pos, cost] = rhs.eval(lhs.y); res.cost = lhs.cost + cost; res.y = pos; } else { if(max(lhs.l, rhs.l) < min(lhs.r, rhs.r)) { res = rhs; res.l = max(lhs.l, rhs.l); res.r = min(lhs.r, rhs.r); } else { res.l = lhs.l, res.r = lhs.r, res.type = 1; if(rhs.l >= lhs.r) { res.x = rhs.l; } else { res.x = rhs.r; } tie(res.y, res.cost) = rhs.eval(res.x); } } return res; } } t[N * 4]; void upd(int pos, node x, int v = 1, int tl = 0, int tr = n) { if(tr - tl == 1) { assert(pos == tl); t[v] = x; return; } int tm = (tl + tr) / 2; if(pos < tm) upd(pos, x, v * 2, tl, tm); else upd(pos, x, v * 2 + 1, tm, tr); t[v] = t[v * 2] + t[v * 2 + 1]; } void upd(int i, int l, int r) { l -= i, r -= i; upd(i, node(l, r)); } node qry(int l, int r, int v = 1, int tl = 0, int tr = n) { if(l <= tl && tr <= r) return t[v]; int tm = (tl + tr) / 2; if(r <= tm) return qry(l, r, v * 2, tl, tm); else if(l >= tm) return qry(l, r, v * 2 + 1, tm, tr); else return qry(l, r, v * 2, tl, tm) + qry(l, r, v * 2 + 1, tm, tr); } } t1, t2; signed main() { IO_OP; cin >> n >> q; for(int i = 0; i < n - 1; i++) { int l, r; cin >> l >> r; r--; t1.upd(i, l, r); t2.upd(n - i - 1, l, r); } while(q--) { int op; cin >> op; if(op == 1) { int p, l, r; cin >> p >> l >> r; r--; p--; t1.upd(p, l, r); t2.upd(n - p - 1, l, r); } else { int a, b, c, d; cin >> a >> b >> c >> d; a--, c--; if(a == c) { cout << max(b - d, 0) << '\n'; } else if(a < c) { b -= a, d -= c; auto u = t1.qry(a, c); auto [pos, cost] = u.eval(b); cost += max(pos - d, 0); cout << cost << '\n'; } else { // a > c a--; a = n - a - 1, c = n - c - 1; c++; b -= a, d -= c; auto u = t2.qry(a, c); auto [pos, cost] = u.eval(b); cost += max(pos - d, 0); cout << cost << '\n'; } } } }

Compilation message (stderr)

timeleap.cpp: In member function 'std::pair<long long int, long long int> DS::node::eval(ll)':
timeleap.cpp:47:27: error: no matching function for call to 'max(int, ll)'
   47 |    ans += max(0, pre - pos);
      |                           ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from timeleap.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:
timeleap.cpp:47:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   47 |    ans += max(0, pre - pos);
      |                           ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from timeleap.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:
timeleap.cpp:47:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   47 |    ans += max(0, pre - pos);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from timeleap.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:
timeleap.cpp:47:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |    ans += max(0, pre - pos);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from timeleap.cpp:1:
/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:
timeleap.cpp:47:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |    ans += max(0, pre - pos);
      |                           ^
timeleap.cpp:51:28: error: no matching function for call to 'max(int, ll)'
   51 |     ans += max(0, pre - pos);
      |                            ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from timeleap.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:
timeleap.cpp:51:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   51 |     ans += max(0, pre - pos);
      |                            ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from timeleap.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:
timeleap.cpp:51:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   51 |     ans += max(0, pre - pos);
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from timeleap.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:
timeleap.cpp:51:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   51 |     ans += max(0, pre - pos);
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from timeleap.cpp:1:
/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:
timeleap.cpp:51:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   51 |     ans += max(0, pre - pos);
      |                            ^
timeleap.cpp: In function 'DS::node operator+(DS::node, DS::node)':
timeleap.cpp:60:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |     auto [pos, cost] = rhs.eval(lhs.y);
      |          ^
timeleap.cpp: In function 'int main()':
timeleap.cpp:139:25: error: no matching function for call to 'max(ll, int)'
  139 |     cout << max(b - d, 0) << '\n';
      |                         ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from timeleap.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:
timeleap.cpp:139:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  139 |     cout << max(b - d, 0) << '\n';
      |                         ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from timeleap.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:
timeleap.cpp:139:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  139 |     cout << max(b - d, 0) << '\n';
      |                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from timeleap.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:
timeleap.cpp:139:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  139 |     cout << max(b - d, 0) << '\n';
      |                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from timeleap.cpp:1:
/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:
timeleap.cpp:139:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  139 |     cout << max(b - d, 0) << '\n';
      |                         ^
timeleap.cpp:143:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  143 |     auto [pos, cost] = u.eval(b);
      |          ^
timeleap.cpp:144:27: error: no matching function for call to 'max(std::tuple_element<0, std::pair<long long int, long long int> >::type, int)'
  144 |     cost += max(pos - d, 0);
      |                           ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from timeleap.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:
timeleap.cpp:144:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  144 |     cost += max(pos - d, 0);
      |                           ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from timeleap.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:
timeleap.cpp:144:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  144 |     cost += max(pos - d, 0);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from timeleap.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:
timeleap.cpp:144:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  144 |     cost += max(pos - d, 0);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from timeleap.cpp:1:
/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:
timeleap.cpp:144:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  144 |     cost += max(pos - d, 0);
      |                           ^
timeleap.cpp:152:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  152 |     auto [pos, cost] = u.eval(b);
      |          ^
timeleap.cpp:153:27: error: no matching function for call to 'max(std::tuple_element<0, std::pair<long long int, long long int> >::type, int)'
  153 |     cost += max(pos - d, 0);
      |                           ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from timeleap.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:
timeleap.cpp:153:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  153 |     cost += max(pos - d, 0);
      |                           ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from timeleap.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:
timeleap.cpp:153:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  153 |     cost += max(pos - d, 0);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from timeleap.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:
timeleap.cpp:153:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  153 |     cost += max(pos - d, 0);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from timeleap.cpp:1:
/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:
timeleap.cpp:153:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  153 |     cost += max(pos - d, 0);
      |                           ^