#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LIM = 1000000000000000;
struct PST{
struct Node{
Node *l, *r;
ll s, e;
int created;
int val;
Node(){
l = r = nullptr;
}
Node(ll s, ll e, int created): s(s), e(e), created(created){
// printf("New node: %d %d %d\n", s, e, created);
l = r = nullptr;
val = 0;
}
Node* decent(int c){
Node* ret = new Node(s, e, c);
ret->val = val;
ret->l = l, ret->r = r;
return ret;
}
~Node(){
if(l && created == l->created) delete l;
if(r && created == r->created) delete r;
}
void addPoint(int x){
if(s==e){
val++;
return;
}
ll m = (s+e+LIM+LIM)/2-LIM;
if(x <= m){
if(l && l->created == created){}
else if(l) l = l->decent(created);
else l = new Node(s, m, created);
l->addPoint(x);
}
else{
if(r && r->created == created){}
else if(r) r = r->decent(created);
else r = new Node(m+1, e, created);
r->addPoint(x);
}
val = (l ? l->val : 0) + (r ? r->val : 0);
}
int sum(ll rs, ll re){
if(rs <= s && e <= re) return val;
ll m = (s+e+LIM+LIM)/2-LIM;
int ret = 0;
if(rs <= m && l) ret += l->sum(rs, re);
if(m < re && r) ret += r->sum(rs, re);
return ret;
}
};
int sz;
Node* root[250002];
vector<ll> locList;
PST(){
sz = 0;
locList.push_back(-1e10);
root[0] = new Node(-2e9, 2e9, 0);
}
void deleteNodes(){
for(int i=sz; i>=0; i--) delete root[i];
}
void addPoint(ll x, ll y){
if(locList.back() != x){
root[sz+1] = root[sz]->decent(sz);
sz++;
locList.push_back(x);
}
root[sz]->addPoint(y);
}
int sum(ll xs, ll xe, ll ys, ll ye){
xe = upper_bound(locList.begin(), locList.end(), xe) - locList.begin() - 1;
xs = lower_bound(locList.begin(), locList.end(), xs) - locList.begin() - 1;
return root[xe]->sum(ys, ye) - root[xs]->sum(ys, ye);
}
} tree;
int n, k;
pair<ll, ll> arr[250002];
int cnt[250002];
ll minDist[250002];
priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > pq;
int main(){
scanf("%d %d", &n, &k);
for(int i=1; i<=n; i++){
scanf("%lld %lld", &arr[i].first, &arr[i].second);
ll tx = arr[i].first, ty = arr[i].second;
arr[i].first = tx + ty, arr[i].second = tx - ty;
}
sort(arr+1, arr+n+1);
for(int i=1; i<=n; i++){
tree.addPoint(arr[i].first, arr[i].second);
}
for(int i=1; i<=n; i++){
ll MIN = 0, MAX = 2e9, ANS = 2e9;
cnt[i]++;
while(MIN <= MAX){
ll MID = (MIN + MAX) / 2;
if(tree.sum(arr[i].first - MID, arr[i].first + MID, arr[i].second - MID, arr[i].second + MID) > cnt[i]){
ANS = MID;
MAX = MID-1;
}
else MIN = MID+1;
}
minDist[i] = ANS;
pq.push(make_pair(ANS, i));
}
k *= 2;
while(k--){
assert(!pq.empty());
pair<ll, int> p = pq.top(); pq.pop();
if(k%2) printf("%lld\n", p.first);
int i = p.second;
cnt[i]++;
if(cnt[i] == n) continue;
ll MIN = 0, MAX = 2e9, ANS = 2e9;
while(MIN <= MAX){
ll MID = (MIN + MAX) / 2;
if(tree.sum(arr[i].first - MID, arr[i].first + MID, arr[i].second - MID, arr[i].second + MID) > cnt[i]){
ANS = MID;
MAX = MID-1;
}
else MIN = MID+1;
}
minDist[i] = ANS;
pq.push(make_pair(ANS, i));
}
tree.deleteNodes();
}
Compilation message
road_construction.cpp: In function 'int main()':
road_construction.cpp:103:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
103 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
road_construction.cpp:105:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | scanf("%lld %lld", &arr[i].first, &arr[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6904 ms |
4516 KB |
Output is correct |
2 |
Correct |
7081 ms |
4508 KB |
Output is correct |
3 |
Incorrect |
5267 ms |
4036 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10111 ms |
401892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10114 ms |
400424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10114 ms |
400424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6904 ms |
4516 KB |
Output is correct |
2 |
Correct |
7081 ms |
4508 KB |
Output is correct |
3 |
Incorrect |
5267 ms |
4036 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6904 ms |
4516 KB |
Output is correct |
2 |
Correct |
7081 ms |
4508 KB |
Output is correct |
3 |
Incorrect |
5267 ms |
4036 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |