Submission #607588

#TimeUsernameProblemLanguageResultExecution timeMemory
607588evenvalueHighway Tolls (IOI18_highway)C++17
51 / 100
170 ms15996 KiB
#include "highway.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template<typename T> using max_heap = priority_queue<T, vector<T>, less<T>>; using int64 = long long; using ld = long double; constexpr int kInf = 1e9 + 10; constexpr int64 kInf64 = 1e15 + 10; constexpr int kMod = 1e9 + 7; void tree_subtasks(const int n, const vector<int> &u, const vector<int> &v, const int a, const int b) { const int m = u.size(); vector<int> w(m); int64 all_0 = ask(w); int lo = 0, hi = m - 1; while (lo < hi) { const int mid = (lo + hi) / 2; fill(w.begin() + mid + 1, w.begin() + hi + 1, 1); const int64 this_query = ask(w); fill(w.begin() + mid + 1, w.begin() + hi + 1, 0); if (this_query > all_0) { lo = mid + 1; } else { hi = mid; } } vector<vector<pair<int, int>>> g(n); for (int i = 0; i < m; i++) { const int x = u[i], y = v[i]; g[x].emplace_back(y, i); g[y].emplace_back(x, i); } auto find_s_t = [&](const int s, const int p) { vector<int> w(m); function<void(int, int)> dfs1 = [&](const int x, const int p) { for (const auto &[y, i] : g[x]) { if (y == p) continue; w[i] = 1; dfs1(y, x); } }; dfs1(s, p); const int64 this_1 = ask(w); const int depth = (this_1 - all_0) / (b - a); if (depth == 0) { return s; } vector<pair<int, int>> candidates; function<void(int, int, int, int)> dfs2 = [&](const int x, const int par, const int d, const int idx) { if (d == depth) { candidates.emplace_back(x, idx); return; } for (const auto &[y, i] : g[x]) { if (y == par) continue; dfs2(y, x, d + 1, i); } }; dfs2(s, p, 0, -1); fill(w.begin(), w.end(), 0); int lo = 0, hi = (int) candidates.size() - 1; while (lo < hi) { const int mid = (lo + hi) / 2; for (int i = lo; i <= mid; i++) { w[candidates[i].second] = 1; } for (int i = mid + 1; i <= hi; i++) { w[candidates[i].second] = 0; } if (ask(w) > all_0) { hi = mid; } else { lo = mid + 1; } } return candidates[lo].first; }; answer(find_s_t(u[lo], v[lo]), find_s_t(v[lo], u[lo])); } void subtask5(const int n, const vector<int> &u, const vector<int> &v, const int a, const int b) { const int m = u.size(); auto different_sets = [&](const vector<int> &partition)-> bool { static vector<int> w(m); for (int i = 0; i < n; i++) { w[i] = (partition[u[i]] == partition[v[i]]); } return (ask(w) & 1); }; int xor_st = 0; vector<int> partition(n), zeros; for (int bit = 0; bit < 20; bit++) { for (int i = 0; i < n; i++) { partition[i] = (i & (1 << bit)); } const int c = different_sets(partition); if (xor_st == 0 and c == 1) { for (int i = 0; i < n; i++) { if (partition[i]) continue; zeros.push_back(i); } } xor_st += c * (1 << bit); } int lo = 0, hi = zeros.size() - 1; fill(partition.begin(), partition.end(), 1); for (const int x : zeros) { partition[x] = 0; } while (lo < hi) { const int mid = (lo + hi) / 2; for (int i = lo; i <= mid; i++) { partition[i] = 0; } for (int i = mid + 1; i <= hi; i++) { partition[i] = 1; } if (different_sets(partition)) { hi = mid; } else { lo = mid + 1; } } answer(lo, lo ^ xor_st); } void find_pair(const int n, const vector<int> u, const vector<int> v, const int a, const int b) { const int m = u.size(); if (m == n - 1) tree_subtasks(n, u, v, a, b); else if (a == 1 and b == 2) subtask5(n, u, v, a, b); else assert(false); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...