Submission #330810

#TimeUsernameProblemLanguageResultExecution timeMemory
330810two_sidesFeast (NOI19_feast)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; struct block { ll val; block *prev, *next; block(ll val): val(val) { prev = next = nullptr; } }; struct compare { bool operator () (const block *x, const block *y) { return abs(x->val) != abs(y->val) ? abs(x->val) < abs(y->val) : x < y; } }; const int N = 3e5 + 5; set <block*, compare> blocks; int a[N]; block *b[N]; bool sign(const int &x) { return x <= 0 ? 0 : 1; } int main() { cin.tie(0)->sync_with_stdio(0); int n, k, m = 0, p = 0; cin >> n >> k; for (int i = 1; i <= n; cin >> a[i++]); for (int i = 1; i <= n; ) { int j = i; ll sum = 0; while (j <= n && sign(a[i]) == sign(a[j])) sum += a[j++]; if (sum > 0 || m) { b[m++] = new block(sum); blocks.insert(b[m - 1]); } i = j; p += sum > 0; } for (int i = 1; i < m; i++) { b[i]->prev = b[i - 1]; b[i - 1]->next = b[i]; } while (p > k && blocks.size()) { block *it = *blocks.begin(); blocks.erase(it); if (it->val > 0) p--; if (it->prev) { blocks.erase(it->prev); if (it->prev->val > 0) p--; it->val += it->prev->val; it->prev = it->prev->prev; } if (it->next) { blocks.erase(it->next); if (it->next->val > 0) p--; it->val += it->next->val; it->next = it->next->next; } if (it->val > 0 || (it->prev && it->next)) { if (it->val > 0) p++; blocks.insert(it); } } ll res = 0; for (auto it : blocks) res += max(0ll, it->val); cout << res << '\n'; }

Compilation message (stderr)

In file included from /usr/include/c++/9/map:60,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:81,
                 from feast.cpp:1:
/usr/include/c++/9/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type) [with _Key = block*; _Val = block*; _KeyOfValue = std::_Identity<block*>; _Compare = compare; _Alloc = std::allocator<block*>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type = const std::_Rb_tree_node<block*>*]':
/usr/include/c++/9/bits/stl_tree.h:2095:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = block*; _Val = block*; _KeyOfValue = std::_Identity<block*>; _Compare = compare; _Alloc = std::allocator<block*>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = block*]'
/usr/include/c++/9/bits/stl_tree.h:2148:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = block* const&; _Key = block*; _Val = block*; _KeyOfValue = std::_Identity<block*>; _Compare = compare; _Alloc = std::allocator<block*>]'
/usr/include/c++/9/bits/stl_set.h:511:48:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = block*; _Compare = compare; _Alloc = std::allocator<block*>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<block*>; std::set<_Key, _Compare, _Alloc>::value_type = block*]'
feast.cpp:44:35:   required from here
/usr/include/c++/9/bits/stl_tree.h:780:8: error: static assertion failed: comparison object must be invocable as const
  780 |        is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~