Submission #755765

#TimeUsernameProblemLanguageResultExecution timeMemory
755765Dan4LifeRoad Construction (JOI21_road_construction)C++17
12 / 100
890 ms9640 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define sz(a) (int)a.size() #define all(a) begin(a),end(a) const int mxN = (int)2.5e5+10; int n, K; vector<int> ans; vector<array<int,2>> v; int calc(int i, int j){ return max(abs(v[i][0]-v[j][0]),abs(v[i][1]-v[j][1])); } bool chk(int d){ set<pair<int,int>> S; S.clear(); ans.clear(); for(int i=0, j=0; i < n and sz(ans)<K; i++){ while(v[i][0]-v[j][0]>d) S.erase({v[j][1],j}), j++; auto itr1 = S.lower_bound({v[i][1]-d,-1}); auto itr2 = S.lower_bound({v[i][1]+d+1,-1}); while(itr1!=end(S) and sz(ans)<K and itr1->first < v[i][1]+d) ans.pb(calc(itr1->second,i)), itr1++; S.insert({v[i][1],i}); } return sz(ans)>=K; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> K; int x, y; for(int i = 0; i < n; i++) cin >> x >> y, v.pb({x+y,x-y}); sort(all(v)); int l = 0, r = (int)4e9; while(l<r){ int mid = (l+r)>>1; if(chk(mid)) r=mid; else l=mid+1; } chk(l); sort(all(ans)); while(sz(ans)<K) ans.pb(l); for(auto u : ans) cout << u << "\n"; }

Compilation message (stderr)

road_construction.cpp: In function 'bool chk(long long int)':
road_construction.cpp:19:8: warning: variable 'itr2' set but not used [-Wunused-but-set-variable]
   19 |   auto itr2 = S.lower_bound({v[i][1]+d+1,-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...