제출 #945957

#제출 시각아이디문제언어결과실행 시간메모리
945957itslqRoad Construction (JOI21_road_construction)C++17
0 / 100
1244 ms2097272 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int N, K, X, Y; vector<int> x, y; vector<vector<int>> fenwick; void update(int x, int y1, bool b) { for (; x <= X; x += x & -x) { for (int y = y1; y <= Y; y += y & -y) { if (b) fenwick[x][y]++; else fenwick[x][y]--; } } } int query(int x, int y1) { int S = 0; for (; x > 0; x -= x & -x) { for (int y = y1; y > 0; y -= y & -y) { S += fenwick[x][y]; } } return S; } bool check(int d) { int x1, y1, S = 0, ia, ib, ic, id; vector<int> xcrit, xdisc, ycrit, ydisc; for (int i = 0; i < N; i++) { x1 = x[i]; y1 = y[i]; xcrit.push_back(x1 - y1 - d); xcrit.push_back(x1 - y1); xcrit.push_back(x1 - y1 + d); ycrit.push_back(x1 + y1 - d); ycrit.push_back(x1 + y1); ycrit.push_back(x1 + y1 + d); } xdisc = xcrit; ydisc = ycrit; sort(xdisc.begin(), xdisc.end()); sort(ydisc.begin(), ydisc.end()); xdisc.erase(unique(xdisc.begin(), xdisc.end()), xdisc.end()); ydisc.erase(unique(ydisc.begin(), ydisc.end()), ydisc.end()); X = xdisc.size(); Y = ydisc.size(); fenwick = vector<vector<int>>(X + 1, vector<int>(Y + 1)); for (int i = 0; i < N; i++) { x1 = x[i]; y1 = y[i]; ia = lower_bound(xdisc.begin(), xdisc.end(), x1 - y1) - xdisc.begin() + 1; ib = lower_bound(ydisc.begin(), ydisc.end(), x1 + y1) - ydisc.begin() + 1; if ((S += query(ia, ib)) >= K) return true; ia = lower_bound(xdisc.begin(), xdisc.end(), x1 - y1 - d) - xdisc.begin() + 1; ib = lower_bound(xdisc.begin(), xdisc.end(), x1 - y1 + d) - xdisc.begin() + 1; ic = lower_bound(ydisc.begin(), ydisc.end(), x1 + y1 - d) - ydisc.begin() + 1; id = lower_bound(ydisc.begin(), ydisc.end(), x1 + y1 + d) - ydisc.begin() + 1; update(ia, ic, 1); update(ib + 1, ic, 0); update(ia, id + 1, 0); update(ib + 1, id + 1, 1); } return false; } signed main() { cin >> N >> K; x.resize(N); y.resize(N); for (int i = 0; i < N; i++) cin >> x[i] >> y[i]; int l = 0, r = 4e9, m, ans; while (l <= r) { m = (l + r) >> 1; if (check(m)) { ans = m; r = --m; } else { l = ++m; } } cout << ans; }
#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...