#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair
const int NM = 2.5e5, LIM = 2e9, inf = 1e18;
int N, K, x[NM+5], y[NM+5], pos_x[NM+5], pos_y[NM+5];
vector <int> arr_x, arr_y;
vector <int> upd[NM+5];
vector <pair <pii, int> > qry[NM+5];
int bit[NM+5];
set <pii> S;
set <pii>::iterator it;
vector <int> od, dlist;
void update(int p){
while (p <= N){
bit[p]++;
p += p & (-p);
}
}
int get(int p){
int res = 0;
while (p > 0){
res += bit[p];
p -= p & (-p);
}
return res;
}
bool check(int d){
for (int i = 1; i <= N; i++){
qry[i].clear();
bit[i] = 0;
}
for (int i = 1; i <= N; i++){
int lx = lower_bound(arr_x.begin(), arr_x.end(), x[i]-y[i]-d)-arr_x.begin()+1,
rx = upper_bound(arr_x.begin(), arr_x.end(), x[i]-y[i]+d)-arr_x.begin();
int ly = lower_bound(arr_y.begin(), arr_y.end(), x[i]+y[i]-d)-arr_y.begin()+1,
ry = upper_bound(arr_y.begin(), arr_y.end(), x[i]+y[i]+d)-arr_y.begin();
qry[rx].push_back(mp(mp(ly, ry), 1));
qry[lx-1].push_back(mp(mp(ly, ry), -1));
}
int sum = 0;
for (int i = 1; i <= N; i++){
for (int u : upd[i]) update(u);
for (pair <pii, int> q : qry[i])
sum += q.se*(get(q.fi.se)-get(q.fi.fi-1));
}
return sum-N >= 2*K;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> K;
for (int i = 1; i <= N; i++){
cin >> x[i] >> y[i];
arr_x.push_back(x[i]-y[i]);
arr_y.push_back(x[i]+y[i]);
}
sort(arr_x.begin(), arr_x.end()); arr_x.erase(unique(arr_x.begin(), arr_x.end()), arr_x.end());
sort(arr_y.begin(), arr_y.end()); arr_y.erase(unique(arr_y.begin(), arr_y.end()), arr_y.end());
for (int i = 1; i <= N; i++){
pos_x[i] = lower_bound(arr_x.begin(), arr_x.end(), x[i]-y[i])-arr_x.begin()+1;
pos_y[i] = lower_bound(arr_y.begin(), arr_y.end(), x[i]+y[i])-arr_y.begin()+1;
upd[pos_x[i]].push_back(pos_y[i]);
}
int l = 0, r = LIM-1, res = LIM;
while (l <= r){
int mid = l+(r-l)/2;
if (check(mid)){
res = mid;
r = mid-1;
}
else l = mid+1;
}
for (int i = 1; i <= N; i++) od.push_back(i);
sort(od.begin(), od.end(), [&](int i, int j){
return mp(x[i], y[i]) < mp(x[j], y[j]);
});
for (int i : od){
pii cur = mp(y[i]-res, -inf);
while (true){
it = S.upper_bound(cur);
if (it == S.end() || it->fi > y[i]+res) break;
if (it->se < x[i]-res){
S.erase(it);
continue;
}
dlist.push_back(abs(x[i] - it->se) + abs(y[i] - it->fi));
cur = *it;
}
S.insert(mp(y[i], x[i]));
}
sort(dlist.begin(), dlist.end());
for (int i = 0; i < K; i++)
cout << dlist[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
18104 KB |
Output is correct |
2 |
Correct |
57 ms |
18360 KB |
Output is correct |
3 |
Correct |
43 ms |
17360 KB |
Output is correct |
4 |
Correct |
42 ms |
17496 KB |
Output is correct |
5 |
Correct |
39 ms |
16092 KB |
Output is correct |
6 |
Correct |
9 ms |
12632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5279 ms |
92676 KB |
Output is correct |
2 |
Correct |
5254 ms |
92832 KB |
Output is correct |
3 |
Correct |
37 ms |
17660 KB |
Output is correct |
4 |
Correct |
5105 ms |
93260 KB |
Output is correct |
5 |
Correct |
4891 ms |
83532 KB |
Output is correct |
6 |
Correct |
4821 ms |
83000 KB |
Output is correct |
7 |
Correct |
4929 ms |
92196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6236 ms |
90508 KB |
Output is correct |
2 |
Correct |
6341 ms |
87852 KB |
Output is correct |
3 |
Correct |
6 ms |
12124 KB |
Output is correct |
4 |
Correct |
4878 ms |
77020 KB |
Output is correct |
5 |
Correct |
1974 ms |
74240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6236 ms |
90508 KB |
Output is correct |
2 |
Correct |
6341 ms |
87852 KB |
Output is correct |
3 |
Correct |
6 ms |
12124 KB |
Output is correct |
4 |
Correct |
4878 ms |
77020 KB |
Output is correct |
5 |
Correct |
1974 ms |
74240 KB |
Output is correct |
6 |
Correct |
6205 ms |
84488 KB |
Output is correct |
7 |
Correct |
6268 ms |
85060 KB |
Output is correct |
8 |
Correct |
5 ms |
12120 KB |
Output is correct |
9 |
Correct |
6 ms |
12124 KB |
Output is correct |
10 |
Correct |
6093 ms |
87160 KB |
Output is correct |
11 |
Correct |
4862 ms |
82316 KB |
Output is correct |
12 |
Correct |
1873 ms |
64132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
18104 KB |
Output is correct |
2 |
Correct |
57 ms |
18360 KB |
Output is correct |
3 |
Correct |
43 ms |
17360 KB |
Output is correct |
4 |
Correct |
42 ms |
17496 KB |
Output is correct |
5 |
Correct |
39 ms |
16092 KB |
Output is correct |
6 |
Correct |
9 ms |
12632 KB |
Output is correct |
7 |
Correct |
2051 ms |
46264 KB |
Output is correct |
8 |
Correct |
2139 ms |
46248 KB |
Output is correct |
9 |
Correct |
43 ms |
17520 KB |
Output is correct |
10 |
Correct |
1870 ms |
43648 KB |
Output is correct |
11 |
Correct |
1948 ms |
51800 KB |
Output is correct |
12 |
Correct |
670 ms |
43348 KB |
Output is correct |
13 |
Correct |
649 ms |
41372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
18104 KB |
Output is correct |
2 |
Correct |
57 ms |
18360 KB |
Output is correct |
3 |
Correct |
43 ms |
17360 KB |
Output is correct |
4 |
Correct |
42 ms |
17496 KB |
Output is correct |
5 |
Correct |
39 ms |
16092 KB |
Output is correct |
6 |
Correct |
9 ms |
12632 KB |
Output is correct |
7 |
Correct |
5279 ms |
92676 KB |
Output is correct |
8 |
Correct |
5254 ms |
92832 KB |
Output is correct |
9 |
Correct |
37 ms |
17660 KB |
Output is correct |
10 |
Correct |
5105 ms |
93260 KB |
Output is correct |
11 |
Correct |
4891 ms |
83532 KB |
Output is correct |
12 |
Correct |
4821 ms |
83000 KB |
Output is correct |
13 |
Correct |
4929 ms |
92196 KB |
Output is correct |
14 |
Correct |
6236 ms |
90508 KB |
Output is correct |
15 |
Correct |
6341 ms |
87852 KB |
Output is correct |
16 |
Correct |
6 ms |
12124 KB |
Output is correct |
17 |
Correct |
4878 ms |
77020 KB |
Output is correct |
18 |
Correct |
1974 ms |
74240 KB |
Output is correct |
19 |
Correct |
6205 ms |
84488 KB |
Output is correct |
20 |
Correct |
6268 ms |
85060 KB |
Output is correct |
21 |
Correct |
5 ms |
12120 KB |
Output is correct |
22 |
Correct |
6 ms |
12124 KB |
Output is correct |
23 |
Correct |
6093 ms |
87160 KB |
Output is correct |
24 |
Correct |
4862 ms |
82316 KB |
Output is correct |
25 |
Correct |
1873 ms |
64132 KB |
Output is correct |
26 |
Correct |
2051 ms |
46264 KB |
Output is correct |
27 |
Correct |
2139 ms |
46248 KB |
Output is correct |
28 |
Correct |
43 ms |
17520 KB |
Output is correct |
29 |
Correct |
1870 ms |
43648 KB |
Output is correct |
30 |
Correct |
1948 ms |
51800 KB |
Output is correct |
31 |
Correct |
670 ms |
43348 KB |
Output is correct |
32 |
Correct |
649 ms |
41372 KB |
Output is correct |
33 |
Correct |
6596 ms |
89008 KB |
Output is correct |
34 |
Correct |
6601 ms |
88916 KB |
Output is correct |
35 |
Correct |
5805 ms |
84296 KB |
Output is correct |
36 |
Correct |
1717 ms |
102768 KB |
Output is correct |
37 |
Correct |
1809 ms |
84752 KB |
Output is correct |
38 |
Correct |
1905 ms |
85148 KB |
Output is correct |