#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll MAXN = 2.5e5+100;
ll n,k;
pll a[MAXN];
ll BIT[MAXN];
void update(ll i,ll v){
// cout<<"UPD "<<i<<' '<<v<<endl;
for (;i <= n;i += i &-i)BIT[i]+=v;
}
ll get(ll i){
// cout<<"GET "<<i<<endl;
ll res = 0;
for (;i > 0;i -= i &-i)res += BIT[i];
return res;
}
ll query(ll l,ll r){
return get(r) - get(l-1);
}
vector <ll> val;
ll solve(ll x){
ll res = 0;
ll ptr = 1;
for (ll i = 1;i <= n;i ++){
// cout<<i<<endl;
while (a[ptr].fi + x < a[i].fi){
update(lower_bound(val.begin(),val.end(),a[ptr].se) - val.begin() + 1,-1);
ptr++;
}
res += query(lower_bound(val.begin(),val.end(),a[i].se - x) - val.begin()+1,upper_bound(val.begin(),val.end(),a[i].se + x)-val.begin());
update(lower_bound(val.begin(),val.end(),a[i].se) - val.begin() + 1,+1);
}
for (;ptr <= n;ptr ++){
update(lower_bound(val.begin(),val.end(),a[ptr].se) - val.begin() + 1,-1);
}
return res;
}
ll dist(ll x,ll y){
return max(abs(a[x].fi-a[y].fi),abs(a[x].se-a[y].se));
}
void trace(ll x){
vector <ll> ans;
multiset <pll> s;
for (ll i = 1,ptr = 1;i <= n;i ++){
while (a[ptr].fi + x < a[i].fi){
s.erase(MP(a[ptr].se,ptr));
ptr++;
}
for (auto it = s.lower_bound(MP(a[i].se-x,0));it != s.end() && (*it).fi <= a[i].se + x;it++){
// cout<<(*it).se<<' '<<i<<endl;
ans.push_back(dist((*it).se,i));
}
s.insert(MP(a[i].se,i));
}
while (sz(ans) < k)ans.push_back(x+1);
sort(ans.begin(),ans.end());
for (auto x:ans)cout<<x<<'\n';
cout<<'\n';
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);
cin>>n>>k;
for (ll i = 1;i <= n;i ++){
ll x,y;
cin>>x>>y;
a[i] = MP(x+y,x-y);
val.push_back(a[i].se);
}
sort(val.begin(),val.end());
val.resize(unique(val.begin(),val.end())-val.begin());
sort(a+1,a+1+n);
// for (ll i= 1 ;i <= n;i ++)cout<<a[i].fi<<' '<<a[i].se<<'\n';
// cout<<"SOLVE(2) "<<solve(2)<<endl;
ll l = 1;
ll r = 5e9;
ll ans = 0;
while (l <= r){
ll mid = (l + r) >> 1;
// cout<<l<<' '<<r<<' '<<mid<<endl;
if (solve(mid) < k){
ans = mid;
l = mid + 1;
}
else{
r = mid - 1;
}
}
// cout<<"ANS "<<ans<<endl;
trace(ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
7012 KB |
Output is correct |
2 |
Correct |
46 ms |
7116 KB |
Output is correct |
3 |
Correct |
32 ms |
7128 KB |
Output is correct |
4 |
Correct |
39 ms |
7116 KB |
Output is correct |
5 |
Correct |
42 ms |
6096 KB |
Output is correct |
6 |
Correct |
2 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1694 ms |
14384 KB |
Output is correct |
2 |
Correct |
1724 ms |
14408 KB |
Output is correct |
3 |
Correct |
36 ms |
7120 KB |
Output is correct |
4 |
Correct |
1744 ms |
14316 KB |
Output is correct |
5 |
Correct |
1714 ms |
14548 KB |
Output is correct |
6 |
Correct |
1763 ms |
14648 KB |
Output is correct |
7 |
Correct |
1560 ms |
14376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4034 ms |
13240 KB |
Output is correct |
2 |
Correct |
4046 ms |
13252 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1663 ms |
11204 KB |
Output is correct |
5 |
Correct |
1212 ms |
13512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4034 ms |
13240 KB |
Output is correct |
2 |
Correct |
4046 ms |
13252 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1663 ms |
11204 KB |
Output is correct |
5 |
Correct |
1212 ms |
13512 KB |
Output is correct |
6 |
Correct |
4179 ms |
13280 KB |
Output is correct |
7 |
Correct |
3880 ms |
13280 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
3981 ms |
13456 KB |
Output is correct |
11 |
Correct |
1573 ms |
11208 KB |
Output is correct |
12 |
Correct |
1184 ms |
13512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
7012 KB |
Output is correct |
2 |
Correct |
46 ms |
7116 KB |
Output is correct |
3 |
Correct |
32 ms |
7128 KB |
Output is correct |
4 |
Correct |
39 ms |
7116 KB |
Output is correct |
5 |
Correct |
42 ms |
6096 KB |
Output is correct |
6 |
Correct |
2 ms |
2392 KB |
Output is correct |
7 |
Correct |
1630 ms |
11624 KB |
Output is correct |
8 |
Correct |
1509 ms |
11668 KB |
Output is correct |
9 |
Correct |
34 ms |
7112 KB |
Output is correct |
10 |
Correct |
1346 ms |
10844 KB |
Output is correct |
11 |
Correct |
1240 ms |
10592 KB |
Output is correct |
12 |
Correct |
230 ms |
11484 KB |
Output is correct |
13 |
Correct |
395 ms |
10100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
7012 KB |
Output is correct |
2 |
Correct |
46 ms |
7116 KB |
Output is correct |
3 |
Correct |
32 ms |
7128 KB |
Output is correct |
4 |
Correct |
39 ms |
7116 KB |
Output is correct |
5 |
Correct |
42 ms |
6096 KB |
Output is correct |
6 |
Correct |
2 ms |
2392 KB |
Output is correct |
7 |
Correct |
1694 ms |
14384 KB |
Output is correct |
8 |
Correct |
1724 ms |
14408 KB |
Output is correct |
9 |
Correct |
36 ms |
7120 KB |
Output is correct |
10 |
Correct |
1744 ms |
14316 KB |
Output is correct |
11 |
Correct |
1714 ms |
14548 KB |
Output is correct |
12 |
Correct |
1763 ms |
14648 KB |
Output is correct |
13 |
Correct |
1560 ms |
14376 KB |
Output is correct |
14 |
Correct |
4034 ms |
13240 KB |
Output is correct |
15 |
Correct |
4046 ms |
13252 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1663 ms |
11204 KB |
Output is correct |
18 |
Correct |
1212 ms |
13512 KB |
Output is correct |
19 |
Correct |
4179 ms |
13280 KB |
Output is correct |
20 |
Correct |
3880 ms |
13280 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
3981 ms |
13456 KB |
Output is correct |
24 |
Correct |
1573 ms |
11208 KB |
Output is correct |
25 |
Correct |
1184 ms |
13512 KB |
Output is correct |
26 |
Correct |
1630 ms |
11624 KB |
Output is correct |
27 |
Correct |
1509 ms |
11668 KB |
Output is correct |
28 |
Correct |
34 ms |
7112 KB |
Output is correct |
29 |
Correct |
1346 ms |
10844 KB |
Output is correct |
30 |
Correct |
1240 ms |
10592 KB |
Output is correct |
31 |
Correct |
230 ms |
11484 KB |
Output is correct |
32 |
Correct |
395 ms |
10100 KB |
Output is correct |
33 |
Correct |
4377 ms |
17232 KB |
Output is correct |
34 |
Correct |
4366 ms |
17228 KB |
Output is correct |
35 |
Correct |
3693 ms |
16484 KB |
Output is correct |
36 |
Correct |
670 ms |
17220 KB |
Output is correct |
37 |
Correct |
641 ms |
17224 KB |
Output is correct |
38 |
Correct |
1264 ms |
16408 KB |
Output is correct |