Submission #392954

#TimeUsernameProblemLanguageResultExecution timeMemory
392954MlxaRoad Construction (JOI21_road_construction)C++14
6 / 100
5485 ms52060 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; #define int ll #define x first #define y second #define mp make_pair #define mt make_tuple #define all(x) x.begin(), x.end() const int N = 1 << 18, INF = 1e18; const int OPEN = -1, QUERY = 0, CLOSE = 1; template<class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int n, k; pair<int, int> p[N]; iset<pair<int, int>> q; int query(int c) { vector<tuple<int, int, int>> scan; for (int i = 0; i < n; ++i) { scan.emplace_back(p[i].x - c, OPEN, p[i].y); scan.emplace_back(p[i].x, QUERY, p[i].y); scan.emplace_back(p[i].x + c, CLOSE, p[i].y); } sort(all(scan)); q.clear(); int answer = 0; for (auto e : scan) { int x, t, y; tie(x, t, y) = e; if (t == OPEN) { q.insert(mp(y, x + c)); } else if (t == CLOSE) { q.erase(mp(y, x - c)); } else { int lef = q.order_of_key(mp(y - c, -INF)), rig = q.order_of_key(mp(y + c, +INF)); answer += rig - lef - 1; } } assert(answer % 2 == 0); return answer /= 2; } signed main() { #ifdef LC assert(freopen("input.txt", "r", stdin)); #endif ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> p[i].x >> p[i].y; int nx = p[i].x + p[i].y; int ny = p[i].x - p[i].y; p[i].x = nx; p[i].y = ny; // cout << i << " " << nx << " " << ny << endl; } sort(p, p + n); int lef = 0, rig = (int)2e9; while (rig - lef > 1) { int mid = (lef + rig) / 2; if (query(mid) < k) { lef = mid; } else { rig = mid; } } int c = lef; vector<int> answer; vector<tuple<int, int, int>> scan; for (int i = 0; i < n; ++i) { scan.emplace_back(p[i].x - c, OPEN, p[i].y); scan.emplace_back(p[i].x, QUERY, p[i].y); scan.emplace_back(p[i].x + c, CLOSE, p[i].y); } sort(all(scan)); q.clear(); for (auto e : scan) { int x, t, y; tie(x, t, y) = e; if (t == OPEN) { q.insert(mp(y, x + c)); } else if (t == CLOSE) { q.erase(mp(y, x - c)); } else { auto le = q.lower_bound(mp(y - c, -INF)), ri = q.upper_bound(mp(y + c, +INF)); for (auto it = le; it != ri; ++it) { int px = it->y, py = it->x, d = max(abs(px - x), abs(py - y)); if (!d) { continue; } answer.push_back(d); } } } sort(all(answer)); for (int i = 0; i + 1 < (int)answer.size(); i += 2) { assert(answer[i] == answer[i + 1]); } for (int i = 0; i < k; ++i) { if (2 * i < (int)answer.size()) { cout << answer[2 * i] << "\n"; } else { cout << rig << "\n"; } } return 0; }
#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...