Submission #410815

#TimeUsernameProblemLanguageResultExecution timeMemory
410815VictorBall Machine (BOI13_ballmachine)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define per(i, a, b) for (int i = b - 1; i >= (a); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) x.size() #define pb push_back #define umap unordered_map #define uset unordered_set typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef long long ll; const int INF = 1'000'000'007; vii graph[100001]; int pos[100001], cur = 0; map<int, int> empty; int find_lo(int u) { int lo = u; trav(edge, graph[u]) { int w, v; tie(w, v) = edge; w = find_lo(v); edge.first = w; lo = min(lo, w); } sort(all(graph[u])); return lo; } void build(int u) { trav(edge, graph[u]) build(edge.second); empty.emplace(cur, u); pos[u] = cur++; } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int n, q, root, p[100001], jmp[17][100001]; cin >> n >> q; rep(i, 1, n + 1) { cin >> p[i]; if (!p[i]) root = i; graph[p[i]].emplace_back(0, i); } find_lo(root); build(0); rep(j, 1, n + 1) jmp[0][j] = p[j]; rep(i, 1, 17) rep(j, 1, n + 1) jmp[i][j] = jmp[i - 1][jmp[i - 1][j]]; rep(i, 0, q) { int query, val; cin >> query >> val; if (query == 1) { int ans; rep(j, 0, val) { ans = empty.begin()->second; empty.erase(empty.begin()); } cout << ans << endl; } else { int u = val, ans = 0; per(j, 0, 17) if (!empty.count(pos[jmp[j][u]])) { u = jmp[j][u]; ans |= 1 << j; } cout << ans << endl; empty.emplace(pos[u],u); } } return 0; }

Compilation message (stderr)

ballmachine.cpp: In function 'void build(int)':
ballmachine.cpp:44:5: error: reference to 'empty' is ambiguous
   44 |     empty.emplace(cur, u);
      |     ^~~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 ballmachine.cpp:1:
/usr/include/c++/10/bits/range_access.h:281:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(std::initializer_list<_Tp>)'
  281 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:272:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  272 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:263:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  263 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
ballmachine.cpp:27:15: note:                 'std::map<int, int> empty'
   27 | map<int, int> empty;
      |               ^~~~~
ballmachine.cpp: In function 'int main()':
ballmachine.cpp:74:23: error: reference to 'empty' is ambiguous
   74 |                 ans = empty.begin()->second;
      |                       ^~~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 ballmachine.cpp:1:
/usr/include/c++/10/bits/range_access.h:281:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(std::initializer_list<_Tp>)'
  281 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:272:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  272 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:263:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  263 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
ballmachine.cpp:27:15: note:                 'std::map<int, int> empty'
   27 | map<int, int> empty;
      |               ^~~~~
ballmachine.cpp:75:17: error: reference to 'empty' is ambiguous
   75 |                 empty.erase(empty.begin());
      |                 ^~~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 ballmachine.cpp:1:
/usr/include/c++/10/bits/range_access.h:281:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(std::initializer_list<_Tp>)'
  281 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:272:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  272 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:263:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  263 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
ballmachine.cpp:27:15: note:                 'std::map<int, int> empty'
   27 | map<int, int> empty;
      |               ^~~~~
ballmachine.cpp:75:29: error: reference to 'empty' is ambiguous
   75 |                 empty.erase(empty.begin());
      |                             ^~~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 ballmachine.cpp:1:
/usr/include/c++/10/bits/range_access.h:281:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(std::initializer_list<_Tp>)'
  281 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:272:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  272 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:263:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  263 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
ballmachine.cpp:27:15: note:                 'std::map<int, int> empty'
   27 | map<int, int> empty;
      |               ^~~~~
ballmachine.cpp:81:32: error: reference to 'empty' is ambiguous
   81 |             per(j, 0, 17) if (!empty.count(pos[jmp[j][u]])) {
      |                                ^~~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 ballmachine.cpp:1:
/usr/include/c++/10/bits/range_access.h:281:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(std::initializer_list<_Tp>)'
  281 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:272:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  272 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:263:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  263 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
ballmachine.cpp:27:15: note:                 'std::map<int, int> empty'
   27 | map<int, int> empty;
      |               ^~~~~
ballmachine.cpp:86:13: error: reference to 'empty' is ambiguous
   86 |             empty.emplace(pos[u],u);
      |             ^~~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 ballmachine.cpp:1:
/usr/include/c++/10/bits/range_access.h:281:5: note: candidates are: 'template<class _Tp> constexpr bool std::empty(std::initializer_list<_Tp>)'
  281 |     empty(initializer_list<_Tp> __il) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:272:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr bool std::empty(const _Tp (&)[_Nm])'
  272 |     empty(const _Tp (&)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:263:5: note:                 'template<class _Container> constexpr decltype (__cont.empty()) std::empty(const _Container&)'
  263 |     empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
      |     ^~~~~
ballmachine.cpp:27:15: note:                 'std::map<int, int> empty'
   27 | map<int, int> empty;
      |               ^~~~~