#include <bits/stdc++.h>
#define forf(i,a,b) for(int i = a; i<=b; i++)
#define all(v) v.begin(),v.end()
#define comp(v) v.erase(unique(all(v)),v.end())
#define LB(i,v) lower_bound(all(v),i)-v.begin() // 1-based
#define UB(i,v) upper_bound(all(v),i)-v.begin()
#define fi first
#define se second
using namespace std;
typedef long long ll;
int N,K;
ll X[1000001],Y[1000001];
struct dot{
ll x,y,id;
bool operator<(const dot &r) const{
if(x==r.x) return id<r.id;
return x<r.x;
}
} A[1000001];
vector<ll> xl,yl;
ll inf = 1e18;
ll ab(ll x){ return x<0?-x:x;}
struct Node{
int val;
int l,r;
} def = {0,0,0};
struct PST{
vector<Node> node = {def};
int root[1000001];
void update(int now , int prv, int s, int e, int f, int x){
if(s==e) {node[now].val = node[prv].val + x; return; }
int m = s+e>>1;
if(f<=m){
node[now].l = node.size(); node[now].r = node[prv].r;
node.push_back(def);
update(node[now].l,node[prv].l,s,m,f,x);
}
else{
node[now].r = node.size(); node[now].l = node[prv].l;
node.push_back(def);
update(node[now].r,node[prv].r,m+1,e,f,x);
}
node[now].val = node[node[now].l].val+node[node[now].r].val;
}
int query(int now ,int prv, int s, int e, int l ,int r){
if(r<l) return 0;
if(l<=s && e<=r) return node[now].val-node[prv].val;
if(s>r || e<l) return 0;
int m = s+e>>1;
return query(node[now].l,node[prv].l,s,m,l,r)+query(node[now].r,node[prv].r,m+1,e,l,r);
}
} pst;
void init(){
forf(i,1,N){
pst.root[i] = pst.node.size(); pst.node.push_back(def);
pst.update(pst.root[i],pst.root[i-1],1,N,LB(A[i].y,yl)+1,1);
}
}
ll findmin(ll x, ll y , int xs , int count){
ll l = 0;
ll r = 1e12;
ll m;
while(l+1<r){
m = l+r>>1;
int ys = LB(y-m,yl) + 1;
int ye = UB(y+m,yl)-1 + 1;
int xe = UB(x+m,xl)-1 + 1;
int tmp = pst.query(pst.root[xe],pst.root[xs],1,N,ys,ye);
if(tmp >= count) r=m;
else l=m;
}
return r;
}
int cnt[1000001];
void solve(){
init();
priority_queue<pair<ll,int> > pq;
forf(i,1,N) cnt[i] = 1;
forf(i,1,N){
pq.push({-findmin(A[i].x,A[i].y,i,cnt[i]) , i});
cnt[i]++;
}
forf(trash,1,K) {
printf("%lld\n", -pq.top().first);
int i = pq.top().second;
pq.pop();
pq.push({-findmin(A[i].x,A[i].y,i,cnt[i]) , i});
cnt[i]++;
}
}
vector<ll> All;
void naive(){
forf(i,1,N){
forf(j,i+1,N){
All.push_back(max(ab(X[i]-X[j]),ab(Y[i]-Y[j])));
}
}
sort(all(All));
forf(i,0,K-1) printf("%lld\n" , All[i]);
}
int main(){
scanf("%d %d" , &N,&K);
forf(i,1,N) scanf("%lld %lld" , &X[i] , &Y[i]);
forf(i,1,N){
ll x = X[i], y = Y[i];
X[i] = x+y;
Y[i] = x-y;
A[i] = {X[i],Y[i],i};
yl.push_back(Y[i]);
xl.push_back(X[i]);
}
sort(all(yl)); comp(yl);
sort(all(xl));
sort(A+1,A+N+1);
solve();
}
Compilation message
road_construction.cpp: In member function 'void PST::update(int, int, int, int, int, int)':
road_construction.cpp:33:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | int m = s+e>>1;
| ~^~
road_construction.cpp: In member function 'int PST::query(int, int, int, int, int, int)':
road_construction.cpp:50:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | int m = s+e>>1;
| ~^~
road_construction.cpp: In function 'll findmin(ll, ll, int, int)':
road_construction.cpp:67:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
67 | m = l+r>>1;
| ~^~
road_construction.cpp: In function 'int main()':
road_construction.cpp:109:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | scanf("%d %d" , &N,&K);
| ~~~~~^~~~~~~~~~~~~~~~~
road_construction.cpp:110:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
110 | forf(i,1,N) scanf("%lld %lld" , &X[i] , &Y[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1508 ms |
11504 KB |
Output is correct |
2 |
Correct |
1415 ms |
11536 KB |
Output is correct |
3 |
Correct |
1177 ms |
11452 KB |
Output is correct |
4 |
Correct |
1301 ms |
11684 KB |
Output is correct |
5 |
Correct |
1483 ms |
10168 KB |
Output is correct |
6 |
Correct |
12 ms |
8856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8597 ms |
128788 KB |
Output is correct |
2 |
Correct |
8330 ms |
129776 KB |
Output is correct |
3 |
Correct |
1176 ms |
11284 KB |
Output is correct |
4 |
Correct |
4210 ms |
128612 KB |
Output is correct |
5 |
Correct |
5298 ms |
129872 KB |
Output is correct |
6 |
Correct |
5524 ms |
129496 KB |
Output is correct |
7 |
Correct |
4808 ms |
129508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6636 ms |
130752 KB |
Output is correct |
2 |
Correct |
5920 ms |
131680 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2628 ms |
128900 KB |
Output is correct |
5 |
Correct |
2165 ms |
130404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6636 ms |
130752 KB |
Output is correct |
2 |
Correct |
5920 ms |
131680 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2628 ms |
128900 KB |
Output is correct |
5 |
Correct |
2165 ms |
130404 KB |
Output is correct |
6 |
Correct |
5898 ms |
130272 KB |
Output is correct |
7 |
Correct |
5771 ms |
131116 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
6032 ms |
131124 KB |
Output is correct |
11 |
Correct |
2678 ms |
129100 KB |
Output is correct |
12 |
Correct |
2078 ms |
130700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1508 ms |
11504 KB |
Output is correct |
2 |
Correct |
1415 ms |
11536 KB |
Output is correct |
3 |
Correct |
1177 ms |
11452 KB |
Output is correct |
4 |
Correct |
1301 ms |
11684 KB |
Output is correct |
5 |
Correct |
1483 ms |
10168 KB |
Output is correct |
6 |
Correct |
12 ms |
8856 KB |
Output is correct |
7 |
Correct |
9165 ms |
47244 KB |
Output is correct |
8 |
Correct |
9315 ms |
48160 KB |
Output is correct |
9 |
Correct |
1310 ms |
12088 KB |
Output is correct |
10 |
Correct |
3806 ms |
47900 KB |
Output is correct |
11 |
Correct |
4453 ms |
46256 KB |
Output is correct |
12 |
Correct |
2255 ms |
49244 KB |
Output is correct |
13 |
Correct |
2363 ms |
45732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1508 ms |
11504 KB |
Output is correct |
2 |
Correct |
1415 ms |
11536 KB |
Output is correct |
3 |
Correct |
1177 ms |
11452 KB |
Output is correct |
4 |
Correct |
1301 ms |
11684 KB |
Output is correct |
5 |
Correct |
1483 ms |
10168 KB |
Output is correct |
6 |
Correct |
12 ms |
8856 KB |
Output is correct |
7 |
Correct |
8597 ms |
128788 KB |
Output is correct |
8 |
Correct |
8330 ms |
129776 KB |
Output is correct |
9 |
Correct |
1176 ms |
11284 KB |
Output is correct |
10 |
Correct |
4210 ms |
128612 KB |
Output is correct |
11 |
Correct |
5298 ms |
129872 KB |
Output is correct |
12 |
Correct |
5524 ms |
129496 KB |
Output is correct |
13 |
Correct |
4808 ms |
129508 KB |
Output is correct |
14 |
Correct |
6636 ms |
130752 KB |
Output is correct |
15 |
Correct |
5920 ms |
131680 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
2628 ms |
128900 KB |
Output is correct |
18 |
Correct |
2165 ms |
130404 KB |
Output is correct |
19 |
Correct |
5898 ms |
130272 KB |
Output is correct |
20 |
Correct |
5771 ms |
131116 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
6032 ms |
131124 KB |
Output is correct |
24 |
Correct |
2678 ms |
129100 KB |
Output is correct |
25 |
Correct |
2078 ms |
130700 KB |
Output is correct |
26 |
Correct |
9165 ms |
47244 KB |
Output is correct |
27 |
Correct |
9315 ms |
48160 KB |
Output is correct |
28 |
Correct |
1310 ms |
12088 KB |
Output is correct |
29 |
Correct |
3806 ms |
47900 KB |
Output is correct |
30 |
Correct |
4453 ms |
46256 KB |
Output is correct |
31 |
Correct |
2255 ms |
49244 KB |
Output is correct |
32 |
Correct |
2363 ms |
45732 KB |
Output is correct |
33 |
Execution timed out |
10019 ms |
130932 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |