#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct Point {
ll x, y;
friend bool operator<(Point a, Point b) {
return a.y < b.y;
}
};
struct Node {
ll sum;
Node *l, *r;
Node(ll s=0, Node* l=nullptr, Node* r=nullptr)
: sum(s), l(l), r(r) {}
};
Node* build(int a, int b) {
if(a==b) return new Node(0);
Node* m = new Node(0);
int mid = (a+b)/2;
m->l = build(a,mid);
m->r = build(mid+1,b);
return m;
}
Node* update(Node *root, int a, int b, int p, ll val) {
if(b < p || a > p) return root;
if(a==b) {
return new Node(root->sum + val);
}
ll m = (a+b)/2;
Node* newL = update(root->l, a, m, p, val);
Node* newR = update(root->r, m+1, b, p, val);
return new Node(newL->sum + newR->sum, newL, newR);
}
ll query(Node *root, int a, int b, int l, int r) {
if(!r || b < l || r < a) return 0;
if(l <= a && b <= r) return root->sum;
int m = (a+b)/2;
return query(root->l, a, m, l, r) + query(root->r, m+1, b, l, r);
}
ll M = 250'010;
vector<ll> cnt(M,1);
ll n;
ll inf = 1e18;
vector<Point> pkt;
vector<ll> X, Y;
vector<Node*> root(M);
int base = 1<<18;
int numer = 1;
void init() {
for(ll i=0; i<n; ++i) X.push_back(pkt[i].x);
sort(X.begin(), X.end());
for(ll i=0; i<n; ++i) Y.push_back(pkt[i].y);
for(ll i=0; i<n; ++i) {
ll idx = lower_bound(X.begin(), X.end(), pkt[i].x) - X.begin();
root[numer] = update(root[numer-1], 0, base-1, idx, 1);
++numer;
}
}
int amount(vector<ll> &x, ll l, ll r) {
return upper_bound(x.begin(), x.end(), r) - lower_bound(x.begin(), x.end(), l);
}
ll kwadrat(ll x, ll y, ll r) {
ll a = lower_bound(X.begin(), X.end(), x-r) - X.begin();
ll b = upper_bound(X.begin(), X.end(), x+r) - X.begin() - 1;
ll left = lower_bound(Y.begin(), Y.end(), y-r) - Y.begin();
ll right = upper_bound(Y.begin(), Y.end(), y+r) - Y.begin() - 1;
return query(root[right+1], 0, base-1, a,b) - query(root[left],0,base-1,a,b);
}
ll find_nxt(ll i) {
ll lo = 0;
ll hi = 4e9;
if(cnt[i]==n) return inf;
while(lo < hi) {
ll mid = (lo+hi)/2;
if(kwadrat(pkt[i].x, pkt[i].y, mid) > cnt[i]) hi = mid;
else lo = mid+1;
}
cnt[i]++;
return lo;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll k;
cin >> n >> k;
pkt.resize(n);
for(ll i=0; i<n; ++i) {
ll x,y;
cin >> x >> y;
pkt[i] = {x+y,x-y};
}
sort(pkt.begin(), pkt.end());
root[0] = build(0,base-1);
init();
priority_queue<pair<ll, ll>> pq;
for(ll i=0; i<n; ++i) {
pq.push({-find_nxt(i), i});
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |