This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node{
int s, e, m;
int v;
node *l = nullptr, *r;
node(int _s, int _e){
s = _s, e = _e, m = s + (e-s)/2;
v = 0;
}
void make_child(){
if (s != e && l == nullptr) l = new node(s, m), r = new node(m+1, e);
}
int query(int qs, int qe){
if (qs == s && e == qe) return v;
make_child();
if (qe <= m) return l->query(qs, qe);
else if (qs > m) return r->query(qs, qe);
else return l->query(qs, m) + r->query(m+1, qe);
}
void update(int x, int k){
if (s == e) {v += k; return;}
make_child();
if (x <= m) l->update(x, k);
else r->update(x, k);
v = l->v + r->v;
}
};
main(){
int n, k; cin >> n >> k;
pair<int, int> arr[n];
for (int x = 0; x < n; x++){
cin >> arr[x].first >> arr[x].second;
}
//consider manhattan distance trick?
for (int x = 0; x < n; x++){
arr[x] = {arr[x].first + arr[x].second, arr[x].first - arr[x].second};
}
sort(arr, arr+n); //sorted by x-coord
//now chebyshev distance, dist = max of difference
//I want to bsearch, but bsearch only gives location of boundary; I need sum of boundary
/*
int l = 0, r = 8'000'000'000LL, ans = 8'000'000'000LL;
while (l <= r){
int m = (l+r)/2;
int cnt = 0;
node *seg = new node(-4'000'000'000LL, 4'000'000'000LL);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for (int x = 0; x < n; x++){
while (!pq.empty() && pq.top().first <= arr[x].first){
seg->update(arr[ pq.top().second ].second, -1);
pq.pop();
}
cnt += seg->query(arr[x].second - m, arr[x].second + m);
seg->update(arr[x].second, 1);
pq.push({arr[x].first+m+1, x});
}
if (cnt < k){
l = m+1;
}
else{
ans = m;
r = m-1;
}
}
*/
vector<int> clown;
for (int x = 0; x < n; x++){
for (int y = x+1; y <= min(x+k+2, n-1); y++){
clown.push_back( max( abs(arr[x].first - arr[y].first), abs(arr[x].second - arr[y].second) ) );
}
}
sort(clown.begin(), clown.end());
for (int x = 0; x < k; x++) cout << clown[x] << '\n';
}
Compilation message (stderr)
road_construction.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
42 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |