#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 25e4;
const ll inf = 1e18;
mt19937 rng;
struct treap{
ll l,r;
ll x,y;
ll val;
}v[N + 1];
struct point{
ll x,y;
}v2[N];
ll cnt = 1;
ll lid,rid;
ll n,k,cnt2 = 0;
ll ans[N + 1];
void dbgtreap(ll pos){
cout<<pos<<' '<<v[pos].l<<' '<<v[pos].r<<' '<<v[pos].x<<' '<<v[pos].y<<' '<<v[pos].val<<'\n';
if(v[pos].l != 0)dbgtreap(v[pos].l);
if(v[pos].r != 0)dbgtreap(v[pos].r);
}
ll mergetreap(ll l, ll r){
if(l == 0){return r;}
if(r == 0){return l;}
if(v[l].y <= v[r].y){
v[r].l = mergetreap(l, v[r].l);
return r;
}else{
v[l].r = mergetreap(v[l].r, r);
return l;
}
}
void splittreap(ll node, ll nr, ll nr2){
if(node == 0){
lid = 0;
rid = 0;
return;
}
if(v[node].x < nr || (v[node].x == nr && v[node].val <= nr2)){
splittreap(v[node].r, nr, nr2);
v[node].r = lid;
lid = node;
}else{
splittreap(v[node].l, nr, nr2);
v[node].l = rid;
rid = node;
}
}
ll ins(ll p, ll x, ll y, ll val){
if(p == 0){
v[cnt] = {0,0,x,y,val};
cnt++;
return cnt - 1;
}
splittreap(p, x, val);
v[cnt] = {0,0,x,y,val};
p = mergetreap(lid, cnt);
p = mergetreap(p, rid);
cnt++;
return p;
}
ll del(ll p, ll x, ll val){
splittreap(p, x, val - 1);
ll leftside = lid;
ll rightside = rid;
splittreap(rid, x, val);
ll id = mergetreap(leftside, rid);
return id;
}
void add(ll pt,ll x,ll y){
if(pt == 0)return;
if(cnt2 > k)return;
ans[cnt2++] = max(abs(v[pt].x - y),abs(v[pt].val - x));
add(v[pt].l,x,y);
add(v[pt].r,x,y);
}
ll get(ll x){
cnt = 1;
cnt2 = 0;
ll treapid = 0;
ll pt = 0;
for(ll i = 0;i < n;i++){
while(pt < i && v2[pt].x < v2[i].x - x){
treapid = del(treapid,v2[pt].y,v2[pt].x);
pt++;
}
splittreap(treapid,v2[i].y - x,-inf);
ll p1 = lid;
splittreap(rid,v2[i].y + x + 1,-inf);
ll p2 = lid;
ll p3 = rid;
//dbgtreap(p2);
//cout<<"p2 "<<p2<<' '<<i<<' '<<x<<' '<<v2[i].x<<' '<<v2[i].y<<'\n';
add(p2,v2[i].x,v2[i].y);
treapid = mergetreap(p1,p2);
treapid = mergetreap(treapid,p3);
treapid = ins(treapid,v2[i].y,rand()%69420,v2[i].x);
if(cnt2 > k)return cnt2;
}
return cnt2;
}
int main(){
cin>>n>>k;
for(ll i = 0;i < n;i++){
cin>>v2[i].x>>v2[i].y;
v2[i] = {v2[i].x + v2[i].y,v2[i].x - v2[i].y};
}
sort(v2,v2 + n,[&](point a,point b){
return a.x < b.x;
});
ll l = 0,r = inf;
while(l != r){
ll mij = (l + r)/2;
if(get(mij) <= k){
l = mij + 1;
}else r = mij;
}
get(l - 1);
sort(ans,ans + cnt2);
while(cnt2 < k){
ans[cnt2++] = l;
}
for(ll i = 0;i < k;i++){
cout<<ans[i]<<'\n';
}
return 0;
}
///i am losing my mind
Compilation message
road_construction.cpp: In function 'll del(ll, ll, ll)':
road_construction.cpp:67:8: warning: unused variable 'rightside' [-Wunused-variable]
67 | ll rightside = rid;
| ^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
5204 KB |
Output is correct |
2 |
Correct |
127 ms |
5036 KB |
Output is correct |
3 |
Correct |
88 ms |
5016 KB |
Output is correct |
4 |
Correct |
86 ms |
4948 KB |
Output is correct |
5 |
Correct |
115 ms |
3920 KB |
Output is correct |
6 |
Correct |
8 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
367 ms |
20120 KB |
Output is correct |
2 |
Correct |
389 ms |
20128 KB |
Output is correct |
3 |
Correct |
80 ms |
4948 KB |
Output is correct |
4 |
Correct |
323 ms |
20048 KB |
Output is correct |
5 |
Correct |
341 ms |
20024 KB |
Output is correct |
6 |
Correct |
337 ms |
20308 KB |
Output is correct |
7 |
Correct |
310 ms |
19712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
364 ms |
20564 KB |
Output is correct |
2 |
Correct |
369 ms |
20564 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
154 ms |
16840 KB |
Output is correct |
5 |
Correct |
1452 ms |
19256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
364 ms |
20564 KB |
Output is correct |
2 |
Correct |
369 ms |
20564 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
154 ms |
16840 KB |
Output is correct |
5 |
Correct |
1452 ms |
19256 KB |
Output is correct |
6 |
Correct |
514 ms |
20976 KB |
Output is correct |
7 |
Correct |
487 ms |
20816 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
398 ms |
19200 KB |
Output is correct |
11 |
Correct |
154 ms |
18784 KB |
Output is correct |
12 |
Correct |
1594 ms |
21224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
5204 KB |
Output is correct |
2 |
Correct |
127 ms |
5036 KB |
Output is correct |
3 |
Correct |
88 ms |
5016 KB |
Output is correct |
4 |
Correct |
86 ms |
4948 KB |
Output is correct |
5 |
Correct |
115 ms |
3920 KB |
Output is correct |
6 |
Correct |
8 ms |
348 KB |
Output is correct |
7 |
Correct |
1536 ms |
11856 KB |
Output is correct |
8 |
Correct |
1553 ms |
11856 KB |
Output is correct |
9 |
Correct |
87 ms |
4948 KB |
Output is correct |
10 |
Correct |
629 ms |
11124 KB |
Output is correct |
11 |
Correct |
359 ms |
10920 KB |
Output is correct |
12 |
Correct |
1112 ms |
11856 KB |
Output is correct |
13 |
Correct |
912 ms |
10252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
5204 KB |
Output is correct |
2 |
Correct |
127 ms |
5036 KB |
Output is correct |
3 |
Correct |
88 ms |
5016 KB |
Output is correct |
4 |
Correct |
86 ms |
4948 KB |
Output is correct |
5 |
Correct |
115 ms |
3920 KB |
Output is correct |
6 |
Correct |
8 ms |
348 KB |
Output is correct |
7 |
Correct |
367 ms |
20120 KB |
Output is correct |
8 |
Correct |
389 ms |
20128 KB |
Output is correct |
9 |
Correct |
80 ms |
4948 KB |
Output is correct |
10 |
Correct |
323 ms |
20048 KB |
Output is correct |
11 |
Correct |
341 ms |
20024 KB |
Output is correct |
12 |
Correct |
337 ms |
20308 KB |
Output is correct |
13 |
Correct |
310 ms |
19712 KB |
Output is correct |
14 |
Correct |
364 ms |
20564 KB |
Output is correct |
15 |
Correct |
369 ms |
20564 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
154 ms |
16840 KB |
Output is correct |
18 |
Correct |
1452 ms |
19256 KB |
Output is correct |
19 |
Correct |
514 ms |
20976 KB |
Output is correct |
20 |
Correct |
487 ms |
20816 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
398 ms |
19200 KB |
Output is correct |
24 |
Correct |
154 ms |
18784 KB |
Output is correct |
25 |
Correct |
1594 ms |
21224 KB |
Output is correct |
26 |
Correct |
1536 ms |
11856 KB |
Output is correct |
27 |
Correct |
1553 ms |
11856 KB |
Output is correct |
28 |
Correct |
87 ms |
4948 KB |
Output is correct |
29 |
Correct |
629 ms |
11124 KB |
Output is correct |
30 |
Correct |
359 ms |
10920 KB |
Output is correct |
31 |
Correct |
1112 ms |
11856 KB |
Output is correct |
32 |
Correct |
912 ms |
10252 KB |
Output is correct |
33 |
Correct |
3393 ms |
22936 KB |
Output is correct |
34 |
Correct |
3420 ms |
22940 KB |
Output is correct |
35 |
Correct |
1717 ms |
22236 KB |
Output is correct |
36 |
Correct |
2190 ms |
23120 KB |
Output is correct |
37 |
Correct |
1859 ms |
23128 KB |
Output is correct |
38 |
Correct |
2547 ms |
21652 KB |
Output is correct |