#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(a, b) for(size_t a = 0; a < (b); a++)
#define pitem item*
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<ll> vl;
const int N=3e5+10;
const ll SS=1LL<<31;
struct item{
ll val;
int id;
item *l,*r;
};
vi wyn;
vector<pair<ll,ll> >w;
bool bb[N];
vi ans,pom[N];
void Insert(pitem v,ll ind,int x,int xd,ll l=SS*(-1),ll r=SS-1){
v->val+=x;
if(l==r) {v->id=xd;return;}
int sr=l+(r-l)/2;
if(ind>sr){
if(!(v->r)){
pitem xd=new item;
xd->l=nullptr,xd->r=nullptr,xd->val=0;
v->r=xd;
}
Insert(v->r,ind,x,xd,sr+1,r);
}else{
if(!(v->l)){
pitem xd=new item;
xd->l=nullptr,xd->r=nullptr,xd->val=0;
v->l=xd;
}
Insert(v->l,ind,x,xd,l,sr);
}
}
void clear(pitem v){
if(!v) return;
clear(v->l),clear(v->r);
delete v;
}
ll Query(pitem v,ll pocz,ll kon,ll p=SS*(-1),ll k=SS-1){
if(p>kon or k<pocz or !v) return 0;
if(p>=pocz and k<=kon) return v->val;
else{
int sr=p+(k-p)/2;
return Query(v->l,pocz,kon,p,sr)+Query(v->r,pocz,kon,sr+1,k);
}
}
void divide(ll l,ll r,pitem v,int k){
if(!v or (int)wyn.size()==k) return;
if(v->val==0) return;
if(l==r){
wyn.push_back(v->id);
return;
}
int sr=l+(r-l)/2;
divide(l,sr,v->l,k),divide(sr+1,r,v->r,k);
}
void Query2(pitem v,ll pocz,ll kon,int kk,ll p=SS*(-1),ll k=SS-1){
if(p>kon or k<pocz or !v) return;
if(p>=pocz and k<=kon) divide(p,k,v,kk);
else{
int sr=p+(k-p)/2;
Query2(v->l,pocz,kon,kk,p,sr),Query2(v->r,pocz,kon,kk,sr+1,k);
}
}
bool check(int x,ll l){;
int wsk=0;
pitem k=new item;
k->val=0,k->l=nullptr,k->r=nullptr;
ll res=0;
rep(i,w.size()){
if(i and w[i].fi==w[i-1].fi) continue;
int curr=i;
while(w[wsk].fi<w[i].fi-x) Insert(k,w[wsk].se,-1,0),wsk++;
while(curr<(int)w.size() and w[curr].fi==w[i].fi) res+=Query(k,max(SS*(-1LL),(ll)w[curr].se-x),min(SS-1,(ll)w[curr].se+x)),Insert(k,w[curr].se,1,curr),curr++;
}
clear(k);
return res>=l;
}
int bs(ll l){
ll pocz=1,kon=(ll)(1e9)*4;
ll sr,res=0;
while(pocz<=kon){
sr=(pocz+kon)/2;
if(check(sr,l)) res=sr,kon=sr-1;
else pocz=sr+1;
}
return res;
}
void solve(){
int n,il;
cin>>n>>il;
rep(i,n){
int x,y;
cin>>x>>y;
int x1=x-y,y1=x+y;
w.push_back({x1,y1});
}
sort(w.begin(),w.end());
int xd=bs(il);
int x,wsk;
if(xd>1){
x=xd-1;
pitem k=new item;
k->val=0,k->l=nullptr,k->r=nullptr;
wsk=0;
rep(i,w.size()){
if(i and w[i].fi==w[i-1].fi) continue;
int curr=i;
while(w[wsk].fi<w[i].fi-x) Insert(k,w[wsk].se,-1,0),wsk++;
while(curr<(int)w.size() and w[curr].fi==w[i].fi){
Query2(k,max(SS*(-1LL),(ll)w[curr].se-x),min(SS-1,(ll)w[curr].se+x),il),Insert(k,w[curr].se,1,curr);
pom[curr]=wyn;
rep(j,wyn.size()) ans.push_back(max(abs(w[curr].fi-w[wyn[j]].fi),abs(w[curr].se-w[wyn[j]].se)));
curr++;
wyn.clear();
}
}
clear(k);
}
pitem k=new item;
k->val=0,k->l=nullptr,k->r=nullptr;
x=xd,wsk=0;
rep(i,w.size()){
if(i and w[i].fi==w[i-1].fi) continue;
int curr=i;
while(w[wsk].fi<w[i].fi-x) Insert(k,w[wsk].se,-1,0),wsk++;
while(curr<(int)w.size() and w[curr].fi==w[i].fi){
Query2(k,max(SS*(-1LL),(ll)w[curr].se-x),min(SS-1,(ll)w[curr].se+x),il),Insert(k,w[curr].se,1,curr);
rep(j,pom[curr].size()) bb[pom[curr][j]]=1;
rep(j,wyn.size()) if(!bb[wyn[j]] and (int)ans.size()<il) ans.push_back(max(abs(w[curr].fi-w[wyn[j]].fi),abs(w[curr].se-w[wyn[j]].se)));
rep(j,pom[curr].size()) bb[pom[curr][j]]=0;
curr++;
wyn.clear();
if((int)ans.size()==il) break;
}
if((int)ans.size()==il) break;
}
sort(ans.begin(),ans.end());
rep(i,ans.size()) cout<<ans[i]<<"\n";
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
solve();
}
Compilation message
road_construction.cpp: In function 'void solve()':
road_construction.cpp:4:39: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
4 | #define rep(a, b) for(size_t a = 0; a < (b); a++)
| ^
road_construction.cpp:99:2: note: in expansion of macro 'rep'
99 | rep(i,n){
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
14984 KB |
Output is correct |
2 |
Correct |
187 ms |
14992 KB |
Output is correct |
3 |
Runtime error |
5901 ms |
2097156 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10104 ms |
177652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10083 ms |
186112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10083 ms |
186112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
14984 KB |
Output is correct |
2 |
Correct |
187 ms |
14992 KB |
Output is correct |
3 |
Runtime error |
5901 ms |
2097156 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
14984 KB |
Output is correct |
2 |
Correct |
187 ms |
14992 KB |
Output is correct |
3 |
Runtime error |
5901 ms |
2097156 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |