Submission #641940

#TimeUsernameProblemLanguageResultExecution timeMemory
641940maomao90Road Construction (JOI21_road_construction)C++17
6 / 100
378 ms5620 KiB
// Hallelujah, praise the one who set me free // Hallelujah, death has lost its grip on me // You have broken every chain, There's salvation in your name // Jesus Christ, my living hope #include <bits/stdc++.h> using namespace std; #define REP(i, s, e) for (int i = (s); i < (e); i++) #define RREP(i, s, e) for (int i = (s); i >= (e); i--) template <class T> inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;} template <class T> inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;} typedef long long ll; typedef long double ld; #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define SZ(_a) (int) _a.size() #define pb push_back typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<iii> viii; #ifndef DEBUG #define cerr if (0) cerr #endif const int INF = 1000000005; const ll LINF = 1000000000000000005ll; const int MAXN = 250005; int n, k; ii xy[MAXN]; vll ans; bool isPos(ll v) { int lft = 0; set<ii> st; int rk = k; REP (i, 0, n) { auto [x, y] = xy[i]; while (lft < i && x - xy[lft].FI > v) { st.erase({xy[lft].SE, lft}); lft++; } auto ptr = st.lower_bound({y, -1}); auto optr = ptr; while (ptr != st.end() && ptr -> FI - y <= v) { if (--rk <= 0) { return 1; } ptr = next(ptr); } ptr = optr; while (ptr != st.begin() && y - prev(ptr) -> FI <= v) { if (--rk <= 0) { return 1; } ptr = prev(ptr); } st.insert({y, i}); } return 0; } int main() { #ifndef DEBUG ios::sync_with_stdio(0), cin.tie(0); #endif cin >> n >> k; REP (i, 0, n) { int x, y; cin >> x >> y; xy[i] = {x - y, x + y}; } sort(xy, xy + n); ll lo = 0, hi = 4e9 + 5, mid; while (lo < hi) { mid = lo + hi >> 1; if (isPos(mid)) { hi = mid; } else { lo = mid + 1; } } int lft = 0; set<ii> st; lo--; REP (i, 0, n) { auto [x, y] = xy[i]; while (lft < i && (ll) x - xy[lft].FI > lo) { auto ptr = st.find({xy[lft].SE, lft}); assert(ptr != st.end()); st.erase(ptr); lft++; } auto ptr = st.lower_bound({y, -1}); auto optr = ptr; while (ptr != st.end() && (ll) ptr -> FI - y <= lo) { ans.pb(max((ll) x - xy[ptr -> SE].FI, (ll) ptr -> FI - y)); ptr = next(ptr); } ptr = optr; while (ptr != st.begin() && (ll) y - prev(ptr) -> FI <= lo) { ptr = prev(ptr); ans.pb(max((ll) x - xy[ptr -> SE].FI, (ll) y - ptr -> FI)); } st.insert({y, i}); } while (SZ(ans) < k) { ans.pb(lo + 1); } sort(ALL(ans)); for (ll i : ans) { cout << i << '\n'; } return 0; }

Compilation message (stderr)

road_construction.cpp: In function 'int main()':
road_construction.cpp:84:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   84 |         mid = lo + hi >> 1;
      |               ~~~^~~~
#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...