이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 2'000'000'000LL, ans = 2'000'000'000LL;
while (l <= r){
int m = (l+r)/2;
int cnt = 0;
node *seg = new node(-4'000'000'007LL, 4'000'000'007LL);
//cerr << "A";
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';
}
컴파일 시 표준 에러 (stderr) 메시지
road_construction.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
42 | main(){
| ^~~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:61:34: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
61 | int l = 0, r = 2'000'000'000LL, ans = 2'000'000'000LL;
| ^~~
# | 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... |