Submission #605688

#TimeUsernameProblemLanguageResultExecution timeMemory
605688evenvalueHighway Tolls (IOI18_highway)C++17
51 / 100
215 ms262144 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; int subtask2(const int a, const int b, const vector<vector<pair<int, int>>> &g, const int s, const int p, const int m) { vector<int> w(m, 1); const int64 all_1 = ask(w); function<void(int, int)> dfs1 = [&](const int x, const int p) { for (const auto &[y, i] : g[x]) { if (y == p) continue; w[i] = 0; dfs1(y, x); } }; dfs1(s, p); const int64 this_0 = ask(w); const int depth = (int)((all_1 - this_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); const int64 all_0 = (all_1 / b) * a; int lo = 0, hi = 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; } 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(); 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; } } w[lo] = 1; assert(ask(w) == all_0 + b - a); w[lo] = 0; 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); } int s = subtask2(a, b, g, u[lo], v[lo], m); int t = subtask2(a, b, g, v[lo], u[lo], m); answer(s, t); }
#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...