// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
using db = long double;
using str = string;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
template<class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 19;
int main() {
cin.tie(0)->sync_with_stdio(0);
// rotate 45 (x, y) -> (x + y, x - y)
// Change Manhattan Distance to C. Distance (max(∆x, ∆y))
int N, K; cin >> N >> K;
vpl A(N); for(auto& x : A) cin >> x.f >> x.s;
for(auto& x : A) x = mp(x.f + x.s, x.f - x.s);
sort(begin(A), end(A));
V<array<ll, 3>> R;
for(int i = 0; i < N; i++) {
int j = i;
while(j < N && A[i].f == A[j].f) j++;
R.pb(array<ll, 3>{A[i].f, i, j - 1});
i = j - 1;
}
int M = sz(R);
auto dist = [&](const pl &a, const pl &b) -> ll { return max(abs(a.f - b.f), abs(a.s - b.s)); };
iset<pl> B; vl ANS;
auto get = [&](ll d, int t) {
// d -> distance within
// t -> get pairs
int Q = 0;
B = {}; ll ans = 0; vl res;
for(int l = 0, r = 0; r < M; r++) {
// REM l(s)
while(l <= r && (R[r][0] - R[l][0]) > d) {
for(int i = R[l][1]; i <= R[l][2]; i++) B.erase(mp(A[i].s, i));
l++;
}
// ADD r + COUNT PAIRS (for people in r);
for(int i = R[r][1]; i <= R[r][2]; i++) {
B.insert(mp(A[i].s, i));
int li = B.order_of_key(mp(A[i].s - d, -MOD));
int ri = B.order_of_key(mp(A[i].s + d, MOD)) - 1;
ans += ri - li;
if (t) for(int x = li; x <= ri; x++) {
int j = (*B.find_by_order(x)).s;
if (i == j) continue;
Q++;
// cout << i << " " << j << " => " << dist(A[i], A[j]) << nl;
// cout << A[i].f << " " << A[i].s << nl;
// cout << A[j].f << " " << A[j].s << nl;
res.pb(dist(A[i], A[j]));
}
}
}
assert(Q <= 2 * K);
if (t) ANS = res;
// cout << d << " => " << ans << endl;
return ans;
};
ll lo = 0, hi = 5LL * MOD;
while(lo < hi) {
ll mid = (lo + hi) / 2;
if (get(mid, 0) > K) hi = mid;
else lo = mid + 1;
}
get(lo - 1, 1); sort(begin(ANS), end(ANS));
while(sz(ANS) < K) ANS.pb(lo);
for(auto& x : ANS) cout << x << nl;
exit(0-0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
5144 KB |
Output is correct |
2 |
Correct |
48 ms |
5140 KB |
Output is correct |
3 |
Correct |
40 ms |
5148 KB |
Output is correct |
4 |
Correct |
43 ms |
5160 KB |
Output is correct |
5 |
Correct |
44 ms |
4556 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1427 ms |
26916 KB |
Output is correct |
2 |
Correct |
1408 ms |
26920 KB |
Output is correct |
3 |
Correct |
37 ms |
4892 KB |
Output is correct |
4 |
Correct |
1354 ms |
26772 KB |
Output is correct |
5 |
Correct |
1407 ms |
27068 KB |
Output is correct |
6 |
Correct |
1404 ms |
26928 KB |
Output is correct |
7 |
Correct |
1456 ms |
26292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2613 ms |
23684 KB |
Output is correct |
2 |
Correct |
2634 ms |
23680 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1353 ms |
25824 KB |
Output is correct |
5 |
Correct |
2816 ms |
20048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2613 ms |
23684 KB |
Output is correct |
2 |
Correct |
2634 ms |
23680 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1353 ms |
25824 KB |
Output is correct |
5 |
Correct |
2816 ms |
20048 KB |
Output is correct |
6 |
Correct |
2566 ms |
23688 KB |
Output is correct |
7 |
Correct |
2861 ms |
23832 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2733 ms |
23240 KB |
Output is correct |
11 |
Correct |
1359 ms |
25712 KB |
Output is correct |
12 |
Correct |
2533 ms |
20044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
5144 KB |
Output is correct |
2 |
Correct |
48 ms |
5140 KB |
Output is correct |
3 |
Correct |
40 ms |
5148 KB |
Output is correct |
4 |
Correct |
43 ms |
5160 KB |
Output is correct |
5 |
Correct |
44 ms |
4556 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
1499 ms |
13580 KB |
Output is correct |
8 |
Correct |
1486 ms |
14348 KB |
Output is correct |
9 |
Correct |
40 ms |
5152 KB |
Output is correct |
10 |
Correct |
1069 ms |
15900 KB |
Output is correct |
11 |
Correct |
862 ms |
17088 KB |
Output is correct |
12 |
Correct |
899 ms |
14136 KB |
Output is correct |
13 |
Correct |
1120 ms |
14420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
5144 KB |
Output is correct |
2 |
Correct |
48 ms |
5140 KB |
Output is correct |
3 |
Correct |
40 ms |
5148 KB |
Output is correct |
4 |
Correct |
43 ms |
5160 KB |
Output is correct |
5 |
Correct |
44 ms |
4556 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
1427 ms |
26916 KB |
Output is correct |
8 |
Correct |
1408 ms |
26920 KB |
Output is correct |
9 |
Correct |
37 ms |
4892 KB |
Output is correct |
10 |
Correct |
1354 ms |
26772 KB |
Output is correct |
11 |
Correct |
1407 ms |
27068 KB |
Output is correct |
12 |
Correct |
1404 ms |
26928 KB |
Output is correct |
13 |
Correct |
1456 ms |
26292 KB |
Output is correct |
14 |
Correct |
2613 ms |
23684 KB |
Output is correct |
15 |
Correct |
2634 ms |
23680 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1353 ms |
25824 KB |
Output is correct |
18 |
Correct |
2816 ms |
20048 KB |
Output is correct |
19 |
Correct |
2566 ms |
23688 KB |
Output is correct |
20 |
Correct |
2861 ms |
23832 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
2733 ms |
23240 KB |
Output is correct |
24 |
Correct |
1359 ms |
25712 KB |
Output is correct |
25 |
Correct |
2533 ms |
20044 KB |
Output is correct |
26 |
Correct |
1499 ms |
13580 KB |
Output is correct |
27 |
Correct |
1486 ms |
14348 KB |
Output is correct |
28 |
Correct |
40 ms |
5152 KB |
Output is correct |
29 |
Correct |
1069 ms |
15900 KB |
Output is correct |
30 |
Correct |
862 ms |
17088 KB |
Output is correct |
31 |
Correct |
899 ms |
14136 KB |
Output is correct |
32 |
Correct |
1120 ms |
14420 KB |
Output is correct |
33 |
Correct |
4135 ms |
30592 KB |
Output is correct |
34 |
Correct |
4278 ms |
30604 KB |
Output is correct |
35 |
Correct |
3108 ms |
30668 KB |
Output is correct |
36 |
Correct |
2745 ms |
28980 KB |
Output is correct |
37 |
Correct |
2688 ms |
28944 KB |
Output is correct |
38 |
Correct |
3099 ms |
25644 KB |
Output is correct |