Submission #795980

#TimeUsernameProblemLanguageResultExecution timeMemory
795980MattTheNubKeys (IOI21_keys)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; template <class T> using v = vector<T>; #ifdef EVAL #define dbg(...) #define dbg2d(...) #else istream &__cin = cin; #include "../../debug.h" __cinwrapper __cin_wrapper; #include "../../debug.cpp" #endif #include <vector> #define f first #define s second using ll = long long; using int2 = pair<int, int>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct chash { static const int RANDOM; static unsigned hash_f(uint64_t x) { x += RANDOM; x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } static unsigned hash_comb(unsigned a, unsigned b) { return hash_f(a * 31 + b); } int operator()(int x) const { return hash_f(x); } int operator()(ll x) const { return hash_f(x); } template <class T1, class T2> int operator()(pair<T1, T2> x) const { return hash_comb((*this)(x.f), (*this)(x.s)); } int operator()(const string &s) const { int hash = 0; for (char c : s) { hash = hash_comb(c, hash); } return hash; } }; const int chash::RANDOM = rng(); template <class K, class V> using ht = gp_hash_table<K, V, chash>; template <class T> using hs = gp_hash_table<T, null_type, chash>; struct Edg { int u, v, c, i; friend bool operator<(Edg a, Edg b) { return (a.c == b.c) ? (a.i < b.i) : (a.c < b.c); } }; queue<Edg> nxt; v<int2> vis; struct DSU { v<int> e; v<hs<int>> keys; v<set<Edg>> edg; DSU(int n) : keys(n), edg(n) { e = v<int>(n, -1); } int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); } bool same_set(int a, int b) { return get(a) == get(b); } int size(int x) { return -e[get(x)]; } bool unite(int x, int y) { x = get(x); y = get(y); if (x == y) { return false; } if (e[x] > e[y]) { swap(x, y); } e[x] += e[y]; e[y] = x; if (edg[y].size() + keys[y].size() > edg[x].size() + keys[x].size()) { keys[y].swap(keys[x]); edg[y].swap(edg[x]); } for (auto z : keys[y]) { auto it = edg[x].lower_bound({0, 0, z, -1}); while (it != edg[x].end() && it->c == z) { nxt.push(*it); it++; edg[x].erase(prev(it)); } keys[x].insert(z); } for (auto z : edg[y]) { if (keys[x].find(z.c) != keys[x].end()) { nxt.push(z); } else { edg[y].insert(z); } } return true; } }; std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) { int n = r.size(); int m = u.size(); DSU dsu(n); vis.assign(m, {-1, -1}); for (int i = 0; i < m; i++) { dsu.edg[u[i]].insert({u[i], v[i], c[i], i}); dsu.edg[v[i]].insert({v[i], u[i], c[i], i}); if (r[u[i]] == c[i]) { nxt.push({u[i], v[i], c[i], i}); } if (r[v[i]] == c[i]) { nxt.push({v[i], u[i], c[i], i}); } } for (int i = 0; i < n; i++) { dsu.keys[i].insert(r[i]); } while (nxt.size()) { Edg edg = nxt.front(); nxt.pop(); if (vis[edg.i].s != -1 || vis[edg.i].f == edg.u) continue; else if (vis[edg.i].f == -1) { dbg(edg.u, edg.v); vis[edg.i].f = edg.u; } else { dbg(edg.u, edg.v); vis[edg.i].s = edg.u; dsu.unite(edg.u, edg.v); } } dbg(vis); hs<int> components; for (int i = 0; i < n; i++) { components.insert(dsu.get(i)); } for (int i = 0; i < m; i++) { if (vis[i].s == -1 && vis[i].f != -1) { components.erase(dsu.get(vis[i].f)); } } int mn = INT_MAX; for (auto x : components) { mn = min(mn, dsu.size(x)); } hs<int> componentstoo; for (auto x : components) { if (dsu.size(x) == mn) { componentstoo.insert(x); } } vector<int> ans(n, 0); for (int i = 0; i < n; i++) { if (componentstoo.find(dsu.get(i)) != componentstoo.end()) { ans[i] = 1; } } return ans; }

Compilation message (stderr)

keys.cpp:49:40: error: 'gp_hash_table' does not name a type
   49 | template <class K, class V> using ht = gp_hash_table<K, V, chash>;
      |                                        ^~~~~~~~~~~~~
keys.cpp:50:31: error: 'gp_hash_table' does not name a type
   50 | template <class T> using hs = gp_hash_table<T, null_type, chash>;
      |                               ^~~~~~~~~~~~~
keys.cpp:63:5: error: 'hs' was not declared in this scope; did you mean 's'?
   63 |   v<hs<int>> keys;
      |     ^~
      |     s
keys.cpp:63:11: error: template argument 1 is invalid
   63 |   v<hs<int>> keys;
      |           ^~
keys.cpp: In member function 'bool DSU::unite(int, int)':
keys.cpp:82:29: error: invalid types 'int[int]' for array subscript
   82 |     if (edg[y].size() + keys[y].size() > edg[x].size() + keys[x].size()) {
      |                             ^
keys.cpp:82:62: error: invalid types 'int[int]' for array subscript
   82 |     if (edg[y].size() + keys[y].size() > edg[x].size() + keys[x].size()) {
      |                                                              ^
keys.cpp:83:11: error: invalid types 'int[int]' for array subscript
   83 |       keys[y].swap(keys[x]);
      |           ^
keys.cpp:83:24: error: invalid types 'int[int]' for array subscript
   83 |       keys[y].swap(keys[x]);
      |                        ^
keys.cpp:86:23: error: invalid types 'int[int]' for array subscript
   86 |     for (auto z : keys[y]) {
      |                       ^
keys.cpp:87:49: error: no matching function for call to 'std::set<Edg>::lower_bound(<brace-enclosed initializer list>)'
   87 |       auto it = edg[x].lower_bound({0, 0, z, -1});
      |                                                 ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from keys.cpp:1:
/usr/include/c++/10/bits/stl_set.h:829:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key = Edg; _Compare = std::less<Edg>; _Alloc = std::allocator<Edg>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<Edg, Edg, std::_Identity<Edg>, std::less<Edg>, std::allocator<Edg> >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = Edg]'
  829 |       lower_bound(const key_type& __x)
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:829:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const Edg&'}
  829 |       lower_bound(const key_type& __x)
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:833:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::const_iterator std::set<_Key, _Compare, _Alloc>::lower_bound(const key_type&) const [with _Key = Edg; _Compare = std::less<Edg>; _Alloc = std::allocator<Edg>; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<Edg, Edg, std::_Identity<Edg>, std::less<Edg>, std::allocator<Edg> >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = Edg]'
  833 |       lower_bound(const key_type& __x) const
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:833:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const Edg&'}
  833 |       lower_bound(const key_type& __x) const
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:839:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::iterator)(((std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_lower_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::lower_bound(const _Kt&) [with _Kt = _Kt; _Key = Edg; _Compare = std::less<Edg>; _Alloc = std::allocator<Edg>]'
  839 |  lower_bound(const _Kt& __x)
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:839:2: note:   template argument deduction/substitution failed:
keys.cpp:87:49: note:   couldn't deduce template parameter '_Kt'
   87 |       auto it = edg[x].lower_bound({0, 0, z, -1});
      |                                                 ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from keys.cpp:1:
/usr/include/c++/10/bits/stl_set.h:845:2: note: candidate: 'template<class _Kt> decltype ((std::set<_Key, _Compare, _Alloc>::const_iterator)(((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_lower_bound_tr(__x))) std::set<_Key, _Compare, _Alloc>::lower_bound(const _Kt&) const [with _Kt = _Kt; _Key = Edg; _Compare = std::less<Edg>; _Alloc = std::allocator<Edg>]'
  845 |  lower_bound(const _Kt& __x) const
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:845:2: note:   template argument deduction/substitution failed:
keys.cpp:87:49: note:   couldn't deduce template parameter '_Kt'
   87 |       auto it = edg[x].lower_bound({0, 0, z, -1});
      |                                                 ^
keys.cpp:93:11: error: invalid types 'int[int]' for array subscript
   93 |       keys[x].insert(z);
      |           ^
keys.cpp:96:15: error: invalid types 'int[int]' for array subscript
   96 |       if (keys[x].find(z.c) != keys[x].end()) {
      |               ^
keys.cpp:96:36: error: invalid types 'int[int]' for array subscript
   96 |       if (keys[x].find(z.c) != keys[x].end()) {
      |                                    ^
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:126:13: error: invalid types 'int[int]' for array subscript
  126 |     dsu.keys[i].insert(r[i]);
      |             ^
keys.cpp:146:3: error: 'hs' was not declared in this scope; did you mean 's'?
  146 |   hs<int> components;
      |   ^~
      |   s
keys.cpp:146:6: error: expected primary-expression before 'int'
  146 |   hs<int> components;
      |      ^~~
keys.cpp:148:5: error: 'components' was not declared in this scope
  148 |     components.insert(dsu.get(i));
      |     ^~~~~~~~~~
keys.cpp:153:7: error: 'components' was not declared in this scope
  153 |       components.erase(dsu.get(vis[i].f));
      |       ^~~~~~~~~~
keys.cpp:158:17: error: 'components' was not declared in this scope
  158 |   for (auto x : components) {
      |                 ^~~~~~~~~~
keys.cpp:162:6: error: expected primary-expression before 'int'
  162 |   hs<int> componentstoo;
      |      ^~~
keys.cpp:163:17: error: 'components' was not declared in this scope
  163 |   for (auto x : components) {
      |                 ^~~~~~~~~~
keys.cpp:165:7: error: 'componentstoo' was not declared in this scope
  165 |       componentstoo.insert(x);
      |       ^~~~~~~~~~~~~
keys.cpp:170:9: error: 'componentstoo' was not declared in this scope
  170 |     if (componentstoo.find(dsu.get(i)) != componentstoo.end()) {
      |         ^~~~~~~~~~~~~