#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3z2QF2y ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
#define all(a) a.begin(), a.end()
const int _n=250011;
using namespace __gnu_pbds;
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
struct fenwick{
ordered_set bit[_n];
void add(int i,int x,int id){
// 0 based
i+=1;
while(i<_n){
bit[i].insert({x,id});
i+=i&-i;
}
}
int query(int i,int l,int r){
i+=1;
int res=0;
while(i){
res+=bit[i].order_of_key({r+1,0})-bit[i].order_of_key({l,0});
i-=i&-i;
}
return res;
}
};
signed main(){
_3z2QF2y;
int n,k;
cin>>n>>k;
k*=2;
vec(pii) a(n);
rep(i,n) cin>>a[i].fi>>a[i].se;
vi xs,ys;
rep(i,n){
int u=a[i].fi-a[i].se,v=a[i].fi+a[i].se;
xs.pb(u);
ys.pb(v);
}
sort(all(xs));
xs.erase(unique(all(xs)),xs.end());
sort(all(ys));
ys.erase(unique(all(ys)),ys.end());
fenwick bit;
rep(i,n){
int u=a[i].fi-a[i].se,v=a[i].fi+a[i].se;
// print(u,v);
bit.add(lower_bound(all(xs),u)-xs.begin(),v,i+1);
}
// print(bit.query(2,-2,2));
auto eval=[&](int x,int y,int d)->int{
pii u={x-y-d,x+y+d};
pii v={x-y+d,x+y-d};
int sx=u.fi,tx=v.fi;
int sy=v.se,ty=u.se;
auto it=lower_bound(all(xs),sx);
auto ti=upper_bound(all(xs),tx);
int res=0;
if(ti!=xs.begin()){
ti=prev(ti);
tx=ti-xs.begin();
res+=bit.query(tx,sy,ty);
}
if(it!=xs.begin()){
it=prev(it);
sx=it-xs.begin();
res-=bit.query(sx,sy,ty);
}
return res;
};
using T=pair<int,pii>;
priority_queue<T,vec(T),greater<T>> pq;
vi rbe(n,1);
auto push=[&](int i){
int l=1,r=1e15+1;
int c=-1,val=-1;
while(l<=r){
int m=(l+r)/2;
int nval=eval(a[i].fi,a[i].se,m);
if(nval>rbe[i]){
val=nval-rbe[i],c=m,r=m-1;
}else{
l=m+1;
}
}
if(c!=-1){
pq.push({c,{val,i}});
rbe[i]+=val;
}
};
rep(i,n){
push(i);
}
vi pns;
while(k>0){
auto top=pq.top();
pq.pop();
while(top.se.fi--){
pns.pb(top.fi);
k-=1;
}
push(top.se.se);
}
assert(sz(pns)%2==0);
for(int i=0;i<sz(pns);i+=2){
cout<<pns[i]<<"\n";
}
//
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9874 ms |
31292 KB |
Output is correct |
2 |
Execution timed out |
10015 ms |
28904 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10037 ms |
178708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10072 ms |
177576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10072 ms |
177576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9874 ms |
31292 KB |
Output is correct |
2 |
Execution timed out |
10015 ms |
28904 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9874 ms |
31292 KB |
Output is correct |
2 |
Execution timed out |
10015 ms |
28904 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |