#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
bool flag=false;
if(x>y) {x=y;flag|=true;}
return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool flag=false;
if (x<y) {x=y;flag|=true;}
return flag;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e18+7;
const ll mod=1e9+7;
const ll N=2e5+5;
const ld eps=1e-9;
vector<pair<ll,ll>> v;
multiset<ll> ms;
ll n,k;
ll i,j,mn=inf;
map<pair<ll,ll>,bool> vis;
ll dis(ll i,ll j){
return abs(v[i].fr-v[j].fr)+abs(v[i].sc-v[j].sc);
}
bool cmp(const pair<ll,ll> &a, const pair<ll,ll> &b) {
return a.sc < b.sc;
}
void upd_ans(ll i,ll j){
if(vis[{i,j}] || dis(i,j)>=mn)return;
vis[{i,j}]=true;
vis[{j,i}]=true;
ms.ins(dis(i,j));
if(ms.sz>k)ms.erase(--ms.end());
if(ms.sz==k)chmin(mn,*ms.rbegin());
}
void rec(ll l,ll r){
if(r-l<3){
for(i=l;i<r;i++){
for(j=i+1;j<=r;j++)upd_ans(i,j);
}
sort(v.begin()+l,v.begin()+r+1,cmp);
return ;
}
ll m=(l+r)/2;
rec(l,m),rec(m+1,r);
vector<pair<ll,ll>> v2(r-l+1);
merge(v.begin()+l,v.begin()+m+1,v.begin()+m+1,v.begin()+r+1,v2.begin(),cmp);
for(i=l;i<=r;i++)v[i]=v2[i-l];
vll vv;
for(i=l;i<=r;i++){
if(abs(v[i].fr-m)<mn){
for(j=vv.sz-1;j>=0;j--){
if(mn<abs(v[i].sc-v2[j].sc))break;
upd_ans(i,vv[j]);
}
vv.pb(i);
}
}
}
void solve(){
ll i,j;
ll a,b;
cin>>n>>k;
for(i=0;i<n;i++){
cin>>a>>b;
v.pb({a,b});
}
sort(all(v));
rec(0,n-1);
for(auto i : ms) cout<<i<<endl;
}
signed main(){
//start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
*/
Compilation message
road_construction.cpp: In function 'void upd_ans(long long int, long long int)':
road_construction.cpp:64:13: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
64 | if(ms.sz>k)ms.erase(--ms.end());
| ~~~~~^~
road_construction.cpp:65:13: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
65 | if(ms.sz==k)chmin(mn,*ms.rbegin());
| ~~~~~^~~
road_construction.cpp: In function 'void solve()':
road_construction.cpp:92:7: warning: unused variable 'j' [-Wunused-variable]
92 | ll i,j;
| ^
road_construction.cpp: In function 'void fre(std::string)':
road_construction.cpp:38:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:38:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
655 ms |
66204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
727 ms |
75960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
242 ms |
19128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
242 ms |
19128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
655 ms |
66204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
655 ms |
66204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |