Submission #946762

#TimeUsernameProblemLanguageResultExecution timeMemory
946762hmm789Road Construction (JOI21_road_construction)C++14
100 / 100
1625 ms16012 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF 1000000000000000000 #define MOD 1000000007 int n, k, x, y; pair<int, int> a[2500000]; vector<int> ans; int dist(int x, int y) { return max(abs(a[x].first-a[y].first), abs(a[x].second-a[y].second)); } void solve(int d) { ans.clear(); multiset<pair<int, int>> s; int idx = 0; for(int i = 0; i < n; i++) { while(a[i].first - a[idx].first > d) { s.erase({a[idx].second, idx}); idx++; } auto it = s.lower_bound({a[i].second-d, -1}); while(it != s.end() && it->first <= a[i].second+d) { ans.push_back(dist(i, it->second)); if(ans.size() >= k) return; it++; } s.insert({a[i].second, i}); } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 0; i < n; i++) { cin >> x >> y; a[i] = {x+y, x-y}; } sort(a, a+n); int l = 0, r = INF, m; while(l < r) { m = (l+r)/2; solve(m); if(ans.size() >= k) r = m; else l = m+1; } solve(l-1); sort(ans.begin(), ans.end()); while(ans.size() < k) ans.push_back(l); for(int i : ans) cout << i << '\n'; }

Compilation message (stderr)

road_construction.cpp: In function 'void solve(long long int)':
road_construction.cpp:27:27: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   27 |             if(ans.size() >= k) return;
      |                ~~~~~~~~~~~^~~~
road_construction.cpp: In function 'int32_t main()':
road_construction.cpp:47:23: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   47 |         if(ans.size() >= k) r = m;
      |            ~~~~~~~~~~~^~~~
road_construction.cpp:52:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   52 |     while(ans.size() < k) ans.push_back(l);
      |           ~~~~~~~~~~~^~~
#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...