Submission #238810

#TimeUsernameProblemLanguageResultExecution timeMemory
238810JatanaMeetings (IOI18_meetings)C++17
Compilation error
0 ms0 KiB
#include "meetings.h" #include <algorithm> #include <cassert> #define le(v) ((int)v.size()) #define pb push_back #define mp make_pair #define f(i, n) for (int i = 0; i < (n); i++) #define x first #define y second using namespace std; typedef long long ll; struct F { ll c = 0, a = 0, b = 0; }; const ll INF = 1e18; const F eye{0, 0, (ll)INF}; bool operator==(const F &a, const F &b) { return a.c == b.c && a.a == b.a && a.b == b.b; } typedef pair<ll, ll> line; ll eval(line l, ll x) { return l.x * x + l.y; } ll eval(F func, ll x, ll y) { return min(x + func.c, 1LL * func.a * y + func.b); } struct TS { vector<F> func; int n; TS() {} TS(int _n) { n = _n; func.resize(2 * n, eye); } ll get(int i, int tl, int tr, int j) { if (tl + 1 == tr) return eval(func[i], 0, j); int m = (tl + tr) / 2; if (j < m) { return eval(func[i], get(i + 1, tl, m, j), j); } else return eval(func[i], get(i + (m - tl) * 2, m, tr, j), j); } ll get(int j) { return get(0, 0, n, j); } void act(int i, int tl, int tr, F h) { if (func[i] == eye) { func[i] = h; return; } line l1 = mp(func[i].a, func[i].b + h.c); line l2 = mp(h.a, h.b); func[i].c += h.c; l1.y -= func[i].c; l2.y -= func[i].c; int m = (tl + tr) / 2; if (eval(l1, m) > eval(l2, m)) swap(l1, l2); func[i].a = l1.x; func[i].b = l1.y; func[i].b += func[i].c; if (tl + 1 != tr) { if (eval(l2, tl) < eval(l1, tl)) { act(i + 1, tl, m, {0, l2.x, l2.y}); } else act(i + (m - tl) * 2, m, tr, {0, l2.x, l2.y}); } } void app(int i, int tl, int tr, int ql, int qr, F h) { if (tr <= ql || qr <= tl) return; if (ql <= tl && tr <= qr) { act(i, tl, tr, h); } else { int m = (tl + tr) / 2; // assert(func[i] == eye); app(i + 1, tl, m, ql, qr, h); app(i + (m - tl) * 2, m, tr, ql, qr, h); } } }; vector<int> H; vector<int> mx[21]; #include <numeric> int query(int l, int r) { int p = 31 - __builtin_clz(r - l); int a = mx[p][l]; int b = mx[p][r - (1 << p)]; if (H[a] >= H[b]) return a; return b; } void init() { mx[0] = vector<int>(le(H), 0); iota(mx[0].begin(), mx[0].end(), 0); for (int i = 1; i < 21; i++) { mx[i] = mx[i - 1]; for (int j = 0; j < le(H); j++) { int sub = j + (1 << (i - 1)); if (sub < le(H)) { if (H[mx[i - 1][sub]] > H[mx[i][j]]) { mx[i][j] = mx[i - 1][sub]; } } } } } vector<ll> dp[2]; TS sp[2]; vector<int> L; vector<int> R; vector<ll> rez; vector<vector<int>> qs; void process(int l, int r, int m) { for (int id : qs[m]) { // either left or right rez[id] = min( sp[0].get(0, 0, sp[0].n, R[id]) + 1LL * H[m] * (m - L[id] + 1), sp[1].get(0, 0, sp[1].n, L[id]) + 1LL * H[m] * (R[id] - m + 1) ); } dp[0][m] = (m - 1 >= l ? sp[0].get(m - 1) : 0) + H[m]; sp[0].app(0, 0, sp[0].n, m, m + 1, {dp[0][m], 0, (ll)INF}); sp[0].app(0, 0, sp[0].n, m + 1, r, { 1LL * (m - l + 1) * H[m], H[m], dp[0][m] - 1LL * m * H[m] }); // for (int i = m + 1; i < r; i++) { // dp[0][i] = min( // dp[0][i] + 1LL * (m - l + 1) * H[m], // dp[0][m] + 1LL * (i - m) * H[m] // ); // } dp[1][m] = (m + 1 < r ? sp[1].get(m + 1) : 0) + H[m]; sp[1].app(0, 0, sp[1].n, m, m + 1, {dp[1][m], 0, (ll)INF}); sp[1].app(0, 0, sp[1].n, l, m, { 1LL * (r - m) * H[m], -1LL * H[m], dp[1][m] + 1LL * m * H[m] }); } vector<tuple<int, int, int>> work; void go(int l, int r) { if (l >= r) return; if (l + 1 == r) { f(t, 2) { dp[t][l] = H[l]; sp[t].app(0, 0, sp[t].n, l, l + 1, {H[l], 0, (ll)INF}); } for (int id : qs[l]) { rez[id] = H[l]; } return; } int m = query(l, r); // for (int i = l; i < r; i++) // if (H[i] > H[m]) // m = i; go(l, m); go(m + 1, r); work.emplace_back(l, r, m); // for (int i = m - 1; i >= l; i--) { // dp[1][i] = min( // dp[1][i] + 1LL * (r - m) * H[m], // dp[1][m] + 1LL * (m - i) * H[m] // ); // } } vector<ll> minimum_costs(vector<int> _H, vector<int> _L, vector<int> _R) { L = _L; R = _R; H = _H;H = vector<int>(750'000, 3); init(); dp[0].resize(le(H)); dp[1].resize(le(H)); sp[0] = TS(le(H)); sp[1] = TS(le(H)); qs.resize(le(H)); int Q = L.size(); for (int i = 0; i < Q; i++) { // int pos = max_element(H.begin() + L[i], H.begin() + R[i] + 1) - H.begin(); int pos = query(L[i], R[i] + 1); qs[pos].pb(i); } rez.resize(Q, (ll)1e18); // return {}; go(0, le(H)); for (auto ttt : work) { process(get<0>(ttt), get<1>(ttt), get<2>(ttt)); } return rez; }

Compilation message (stderr)

meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:198:12: error: 'std::tuple<int, int, int> ttt' has incomplete type
  for (auto ttt : work) {
            ^~~
In file included from /usr/include/c++/7/vector:69:0,
                 from meetings.h:3,
                 from meetings.cpp:2:
/usr/include/c++/7/bits/vector.tcc: In instantiation of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int&, int&, int&}; _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::vector<_Tp, _Alloc>::reference = std::tuple<int, int, int>&]':
meetings.cpp:169:27:   required from here
/usr/include/c++/7/bits/vector.tcc:102:6: error: cannot increment a pointer to incomplete type 'std::tuple<int, int, int>'
      ++this->_M_impl._M_finish;
      ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/vector:60,
                 from meetings.h:3,
                 from meetings.cpp:2:
/usr/include/c++/7/bits/stl_iterator.h: In instantiation of '__gnu_cxx::__normal_iterator<_Iterator, _Container>& __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++() [with _Iterator = std::tuple<int, int, int>*; _Container = std::vector<std::tuple<int, int, int> >]':
meetings.cpp:198:18:   required from here
/usr/include/c++/7/bits/stl_iterator.h:802:2: error: cannot increment a pointer to incomplete type 'std::tuple<int, int, int>'
  ++_M_current;
  ^~~~~~~~~~~~
In file included from /usr/include/c++/7/vector:64:0,
                 from meetings.h:3,
                 from meetings.cpp:2:
/usr/include/c++/7/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]':
/usr/include/c++/7/bits/stl_vector.h:263:15:   required from 'std::vector<_Tp, _Alloc>::vector() [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]'
meetings.cpp:150:30:   required from here
/usr/include/c++/7/bits/stl_vector.h:163:9: error: invalid use of incomplete type 'class std::tuple<int, int, int>'
       { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage
                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         - this->_M_impl._M_start); }
         ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/move.h:54:0,
                 from /usr/include/c++/7/bits/stl_pair.h:59,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/vector:60,
                 from meetings.h:3,
                 from meetings.cpp:2:
/usr/include/c++/7/type_traits:2555:11: note: declaration of 'class std::tuple<int, int, int>'
     class tuple;
           ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h:33:0,
                 from /usr/include/c++/7/bits/allocator.h:46,
                 from /usr/include/c++/7/vector:61,
                 from meetings.h:3,
                 from meetings.cpp:2:
/usr/include/c++/7/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::tuple<int, int, int>; _Args = {int&, int&, int&}; _Tp = std::tuple<int, int, int>]':
/usr/include/c++/7/bits/alloc_traits.h:475:4:   required from 'static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = std::tuple<int, int, int>; _Args = {int&, int&, int&}; _Tp = std::tuple<int, int, int>; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<std::tuple<int, int, int> >]'
/usr/include/c++/7/bits/vector.tcc:100:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int&, int&, int&}; _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::vector<_Tp, _Alloc>::reference = std::tuple<int, int, int>&]'
meetings.cpp:169:27:   required from here
/usr/include/c++/7/ext/new_allocator.h:136:4: error: invalid use of incomplete type 'class std::tuple<int, int, int>'
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/move.h:54:0,
                 from /usr/include/c++/7/bits/stl_pair.h:59,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/vector:60,
                 from meetings.h:3,
                 from meetings.cpp:2:
/usr/include/c++/7/type_traits:2555:11: note: declaration of 'class std::tuple<int, int, int>'
     class tuple;
           ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h:33:0,
                 from /usr/include/c++/7/bits/allocator.h:46,
                 from /usr/include/c++/7/vector:61,
                 from meetings.h:3,
                 from meetings.cpp:2:
/usr/include/c++/7/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::deallocate(__gnu_cxx::new_allocator<_Tp>::pointer, __gnu_cxx::new_allocator<_Tp>::size_type) [with _Tp = std::tuple<int, int, int>; __gnu_cxx::new_allocator<_Tp>::pointer = std::tuple<int, int, int>*; __gnu_cxx::new_allocator<_Tp>::size_type = long unsigned int]':
/usr/include/c++/7/bits/alloc_traits.h:462:9:   required from 'static void std::allocator_traits<std::allocator<_Tp1> >::deallocate(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, std::allocator_traits<std::allocator<_Tp1> >::pointer, std::allocator_traits<std::allocator<_Tp1> >::size_type) [with _Tp = std::tuple<int, int, int>; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<std::tuple<int, int, int> >; std::allocator_traits<std::allocator<_Tp1> >::pointer = std::tuple<int, int, int>*; std::allocator_traits<std::allocator<_Tp1> >::size_type = long unsigned int]'
/usr/include/c++/7/bits/stl_vector.h:180:19:   required from 'void std::_Vector_base<_Tp, _Alloc>::_M_deallocate(std::_Vector_base<_Tp, _Alloc>::pointer, std::size_t) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::_Vector_base<_Tp, _Alloc>::pointer = std::tuple<int, int, int>*; std::size_t = long unsigned int]'
/usr/include/c++/7/bits/stl_vector.h:162:22:   required from 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]'
/usr/include/c++/7/bits/stl_vector.h:263:15:   required from 'std::vector<_Tp, _Alloc>::vector() [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]'
meetings.cpp:150:30:   required from here
/usr/include/c++/7/ext/new_allocator.h:119:19: error: invalid application of '__alignof__' to incomplete type 'std::tuple<int, int, int>'
  if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
/usr/include/c++/7/ext/new_allocator.h:121:34: error: invalid application of '__alignof__' to incomplete type 'std::tuple<int, int, int>'
      ::operator delete(__p, std::align_val_t(alignof(_Tp)));
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/vector:62:0,
                 from meetings.h:3,
                 from meetings.cpp:2:
/usr/include/c++/7/bits/stl_construct.h: In instantiation of 'void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = std::tuple<int, int, int>*]':
/usr/include/c++/7/bits/stl_construct.h:206:15:   required from 'void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>&) [with _ForwardIterator = std::tuple<int, int, int>*; _Tp = std::tuple<int, int, int>]'
/usr/include/c++/7/bits/stl_vector.h:434:22:   required from 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]'
meetings.cpp:150:30:   required from here
/usr/include/c++/7/bits/stl_construct.h:133:7: error: static assertion failed: value type is destructible
       static_assert(is_destructible<_Value_type>::value,
       ^~~~~~~~~~~~~
/usr/include/c++/7/bits/stl_construct.h:137:11: error: invalid use of incomplete type 'std::iterator_traits<std::tuple<int, int, int>*>::value_type {aka class std::tuple<int, int, int>}'
       std::_Destroy_aux<__has_trivial_destructor(_Value_type)>::
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  __destroy(__first, __last);
  ~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/move.h:54:0,
                 from /usr/include/c++/7/bits/stl_pair.h:59,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/vector:60,
                 from meetings.h:3,
                 from meetings.cpp:2:
/usr/include/c++/7/type_traits:2555:11: note: declaration of 'std::iterator_traits<std::tuple<int, int, int>*>::value_type {aka class std::tuple<int, int, int>}'
     class tuple;
           ^~~~~