Submission #739064

#TimeUsernameProblemLanguageResultExecution timeMemory
739064tch1cherinInside information (BOI21_servers)C++17
Compilation error
0 ms0 KiB
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops","omit-frame-pointer","inline") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/hash_policy.hpp> using namespace std; using namespace __gnu_pbds; struct CustomHash { uint64_t operator()(size_t x) { static uint64_t RANDOM = chrono::steady_clock().now().time_since_epoch().count(); return x ^ RANDOM; } }; struct fenwick { int size; vector<int> fenw, changes; fenwick() {} fenwick(int _size) : size(_size), fenw(_size + 1) {} void add(int i, int v) { for (i++; i <= size; i += i & -i) { fenw[i] += v; changes.push_back(i); } } int prefix_sum(int r) { int ans = 0; for (; r > 0; r -= r & -r) { ans += fenw[r]; } return ans; } int suffix_sum(int l) { return prefix_sum(size) - prefix_sum(l); } void clear() { for (int i : changes) { fenw[i] = 0; } changes.clear(); } }; const int N = 120000; vector<pair<int, int>> graph[N]; // (v, t) vector<tuple<int, int, int, int>> Share[N]; // (a, b, t, id) vector<tuple<int, int, int, int>> Query[N]; // (a, b, t, id) vector<tuple<int, int, int>> Count[N]; // (u, t, id) int sz[N], answer[2 * N], type[N], last[N]; bool used[N]; fenwick bit; gp_hash_table<int, int, CustomHash> s, edge; void sizes(int u, int p) { sz[u] = 1; for (auto [v, t] : graph[u]) { if (v != p && !used[v]) { sizes(v, u); sz[u] += sz[v]; } } } int centroid(int u, int p, int n) { for (auto [v, t] : graph[u]) { if (v != p && !used[v] && sz[v] > n / 2) { return centroid(v, u, n); } } return u; } void DFS(int u, int p, vector<int>& comp) { comp.push_back(u); for (auto [v, t] : graph[u]) { if (v != p && !used[v]) { DFS(v, u, comp); } } } void explore(int u, int p, int time) { s.insert({u, u}); if (type[u] == 0 || type[u] == 1) { bit.add(edge[u], 1); } for (auto [v, t] : graph[u]) { if (v != p && !used[v] && t <= time) { if (type[u] == 0) { type[v] = (last[u] == -1 ? 0 : (last[u] < t ? 1 : 2)); } else if (type[u] == 1) { type[v] = (last[u] < t ? 1 : 3); } else if (type[u] == 2) { type[v] = (last[u] > t ? 2 : 3); } else { type[v] = 3; } last[v] = t; explore(v, u, time); } } } void find_centroids(int u, int p) { gp_hash_table<int, int, CustomHash> first, to; edge[u] = -1; for (auto [v, t] : graph[u]) { if (v != p && !used[v]) { sizes(v, u); to[v] = centroid(v, u, sz[v]); } } for (auto [v, t] : graph[u]) { if (v != p && !used[v]) { vector<int> comp; DFS(v, u, comp); for (int x : comp) { first[x] = v; edge[x] = t; } } } for (auto &[k, v] : first) { v = to[v]; } first[u] = INT_MIN; vector<int> D; for (auto [a, b, t, id] : Share[u]) { D.push_back(t); } for (auto [a, b, t, id] : Query[u]) { D.push_back(t); } for (auto [a, t, id] : Count[u]) { D.push_back(t); } sort(D.begin(), D.end()); D.resize(unique(D.begin(), D.end()) - D.begin()); int share_pos = 0, query_pos = 0, count_pos = 0; s.insert({u, u}); type[u] = 0; last[u] = -1; for (int t : D) { while (share_pos < (int)Share[u].size() && get<2>(Share[u][share_pos]) <= t) { auto [a, b, _t, id] = Share[u][share_pos]; if (first[a] == first[b]) { Share[first[a]].emplace_back(a, b, _t, id); } if (s.find(b) != s.end()) { swap(a, b); } if (s.find(a) != s.end()) { if (type[a] == 0) { type[b] = (last[a] == -1 ? 0 : (last[a] < t ? 1 : 2)); } else if (type[a] == 1) { type[b] = (last[a] < t ? 1 : 3); } else if (type[a] == 2) { type[b] = (last[a] > t ? 2 : 3); } else { type[b] = 3; } last[b] = t; explore(b, a, t); } share_pos++; } while (query_pos < (int)Query[u].size() && get<2>(Query[u][query_pos]) <= t) { auto [a, b, _t, id] = Query[u][query_pos]; if (a == b) { answer[id] = INT_MAX; } else if (first[a] == first[b]) { Query[first[a]].emplace_back(a, b, _t, id); } else { bool good = true; good &= s.find(a) != s.end() && s.find(b) != s.end(); good &= type[a] <= 1; good &= type[b] == 0 || type[b] == 2; good &= edge[a] == -1 || edge[b] == -1 || edge[a] > edge[b]; answer[id] = good ? INT_MAX : INT_MIN; } query_pos++; } while (count_pos < (int)Count[u].size() && get<1>(Count[u][count_pos]) <= t) { auto [a, _t, id] = Count[u][count_pos]; if (a != u) { Count[first[a]].emplace_back(a, _t, id); } if (s.find(a) != s.end()) { if (type[a] == 0 || type[a] == 2) { answer[id] += bit.suffix_sum(edge[a] + 1) + 1; } } count_pos++; } } s.clear(); bit.clear(); edge.clear(); used[u] = true; for (auto [v, t] : graph[u]) { if (v != p && !used[v]) { sizes(v, u); find_centroids(centroid(v, u, sz[v]), u); } } } void solve() { memset(used, 0, sizeof used); memset(answer, 0, sizeof answer); int n, k; cin >> n >> k; bit = fenwick(n); int t = 0; vector<tuple<int, int, int, int>> share_queries, query_queries; vector<tuple<int, int, int>> count_queries; for (int i = 0; i < n + k - 1; i++) { char type; cin >> type; if (type == 'S') { int a, b; cin >> a >> b; a--, b--; t++; graph[a].emplace_back(b, t); graph[b].emplace_back(a, t); share_queries.emplace_back(a, b, t, i); } else if (type == 'Q') { int a, d; cin >> a >> d; a--, d--; query_queries.emplace_back(a, d, t, i - t); } else { int d; cin >> d; d--; count_queries.emplace_back(d, t, i - t); } } sizes(0, -1); int c = centroid(0, -1, n); Share[c] = share_queries; Query[c] = query_queries; Count[c] = count_queries; find_centroids(c, -1); for (int i = 0; i < k; i++) { if (answer[i] == INT_MIN) { cout << "no\n"; } else if (answer[i] == INT_MAX) { cout << "yes\n"; } else { cout << answer[i] << "\n"; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); }

Compilation message (stderr)

In file included from /usr/include/c++/10/ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp:42,
                 from /usr/include/c++/10/ext/pb_ds/detail/container_base_dispatch.hpp:72,
                 from /usr/include/c++/10/ext/pb_ds/assoc_container.hpp:48,
                 from servers.cpp:4:
/usr/include/c++/10/ext/pb_ds/detail/hash_fn/ranged_probe_fn.hpp: In instantiation of '__gnu_pbds::detail::ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, Probe_Fn, false>::size_type __gnu_pbds::detail::ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, Probe_Fn, false>::operator()(__gnu_pbds::detail::ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, Probe_Fn, false>::key_const_reference) const [with Key = int; Hash_Fn = CustomHash; _Alloc = std::allocator<char>; Comb_Probe_Fn = __gnu_pbds::direct_mask_range_hashing<>; Probe_Fn = __gnu_pbds::linear_probe_fn<long unsigned int>; __gnu_pbds::detail::ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, Probe_Fn, false>::size_type = long unsigned int; __gnu_pbds::detail::ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, Probe_Fn, false>::key_const_reference = const int&]':
/usr/include/c++/10/ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp:519:57:   required from '__gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::pointer __gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::find_key_pointer(__gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::key_const_reference, __gnu_pbds::detail::false_type) [with Key = int; Mapped = int; Hash_Fn = CustomHash; Eq_Fn = std::equal_to<int>; _Alloc = std::allocator<char>; bool Store_Hash = false; Comb_Probe_Fn = __gnu_pbds::direct_mask_range_hashing<>; Probe_Fn = __gnu_pbds::linear_probe_fn<long unsigned int>; Resize_Policy = __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int>; __gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::pointer = std::pair<const int, int>*; __gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::key_const_reference = const int&; __gnu_pbds::detail::false_type = std::tr1::integral_constant<int, 0>]'
/usr/include/c++/10/ext/pb_ds/detail/gp_hash_table_map_/find_fn_imps.hpp:49:26:   required from '__gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::point_iterator __gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::find(__gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::key_const_reference) [with Key = int; Mapped = int; Hash_Fn = CustomHash; Eq_Fn = std::equal_to<int>; _Alloc = std::allocator<char>; bool Store_Hash = false; Comb_Probe_Fn = __gnu_pbds::direct_mask_range_hashing<>; Probe_Fn = __gnu_pbds::linear_probe_fn<long unsigned int>; Resize_Policy = __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int>; __gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::point_iterator = __gnu_pbds::detail::gp_ht_map<int, int, CustomHash, std::equal_to<int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator_; __gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::key_const_reference = const int&]'
servers.cpp:156:19:   required from here
/usr/include/c++/10/ext/pb_ds/detail/hash_fn/ranged_probe_fn.hpp:150:69: error: passing 'const __gnu_pbds::detail::ranged_probe_fn<int, CustomHash, std::allocator<char>, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, false>' as 'this' argument discards qualifiers [-fpermissive]
  150 |     { return comb_probe_fn_base::operator()(hash_fn_base::operator()(r_key)); }
      |                                             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
servers.cpp:10:12: note:   in call to 'uint64_t CustomHash::operator()(size_t)'
   10 |   uint64_t operator()(size_t x) {
      |            ^~~~~~~~