Problem p01526 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define EPS (1e-8)
#define N_MAX 200005
using namespace std;
typedef double ll;

int N;
ll R, x[N_MAX], y[N_MAX];
bool used[N_MAX];

struct node {
  vector<ll> Point;
  int l, r;
  node() {}
  node(vector<ll> a) { Point = a, l = r = -1; }
};

const int K = 2; // K:テヲツャツ。テ・ツ?εヲツ閉ー
int D; // D:テ」ツ?敕」ツ?ョテヲツ卍づ」ツ?ォテ」ツつステ」ツδシテ」ツδ暗」ツ?凖」ツつ凝・ツ淞コテヲツコツ姪」ツ?ョテヲツャツ。テ・ツ??
vector<vector<ll>>
    P; // テ」ツ?敕」ツつ古」ツ?榲」ツつ古」ツ?ョティツヲツ?ァツエツ?」ツ?ッK+1テ・ツ??Kテ・ツ?凝」ツ?ョテヲツャツ。テ・ツ?ε」ツ?ョテァツ閉ェテ・ツ渉キテッツシツ凝、ツサツ佚」ツ?妥」ツ?淌」ツ??umber)
vector<node> G;

bool compare(vector<ll> A, vector<ll> B) { return A[D] < B[D]; }

int make_tree(int depth, int l, int r) {
  if (l > r)
    return -1;
  D = depth % K;
  sort(P.begin() + l, P.begin() + r + 1, compare);
  int m = (l + r) / 2, res = G.size();
  G.push_back(node(P[m]));

  int vl = make_tree(depth + 1, l, m - 1);
  int vr = make_tree(depth + 1, m + 1, r);

  G[res].l = vl;
  G[res].r = vr;
  return res;
}

vector<int>
    num; // searchテ」ツ?ァティツヲツ凝」ツ?、テ」ツ?妥」ツつ凝」ツ?禿」ツ?ィテ」ツ?古」ツ?ァテ」ツ?催」ツ?淌ァツつケテ」ツ?ョnumberテ」ツつ津」ツ??」ツつ古」ツつ?

void search(int x, int depth, vector<ll> &L, vector<ll> &R) {
  bool f = true;
  for (int i = 0; i < K; i++)
    if (G[x].Point[i] < L[i] || R[i] < G[x].Point[i])
      f = false;

  if (f)
    num.push_back(G[x].Point[K]);

  D = depth % K;
  if (G[x].Point[D] <= R[D] && G[x].r != -1)
    search(G[x].r, depth + 1, L, R);
  D = depth % K;
  if (L[D] <= G[x].Point[D] && G[x].l != -1)
    search(G[x].l, depth + 1, L, R);
}

int main() {

  cin >> N >> R;

  P.resize(N);

  for (int i = 0; i < N; i++) {

    scanf("%lf %lf", &x[i], &y[i]);

    P[i].resize(K + 1);

    P[i][K] = i;
    P[i][0] = x[i], P[i][1] = y[i];
  }

  make_tree(0, 0, P.size() - 1);

  int ans = 0;
  for (int i = 0; i < N; i++) {

    if (used[i])
      continue;

    vector<ll> L2(K), R2(K);

    L2[0] = x[i] - R - EPS;
    R2[0] = x[i] + R + EPS;

    L2[1] = y[i] - R - EPS;
    R2[1] = y[i] + R + EPS;

    num.clear();

    search(0, 0, L2, R2);

    for (int j = 0; j < num.size(); j++)
      used[num[j]] = 1;

    ans++;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define EPS (1e-8)
#define N_MAX 200005
using namespace std;
typedef double ll;

int N;
ll R, x[N_MAX], y[N_MAX];
bool used[N_MAX];

struct node {
  vector<ll> Point;
  int l, r;
  node() {}
  node(vector<ll> a) { Point = a, l = r = -1; }
};

const int K = 2; // K:テヲツャツ。テ・ツ?εヲツ閉ー
int D; // D:テ」ツ?敕」ツ?ョテヲツ卍づ」ツ?ォテ」ツつステ」ツδシテ」ツδ暗」ツ?凖」ツつ凝・ツ淞コテヲツコツ姪」ツ?ョテヲツャツ。テ・ツ??
vector<vector<ll>>
    P; // テ」ツ?敕」ツつ古」ツ?榲」ツつ古」ツ?ョティツヲツ?ァツエツ?」ツ?ッK+1テ・ツ??Kテ・ツ?凝」ツ?ョテヲツャツ。テ・ツ?ε」ツ?ョテァツ閉ェテ・ツ渉キテッツシツ凝、ツサツ佚」ツ?妥」ツ?淌」ツ??umber)
vector<node> G;

bool compare(const vector<ll> &A, const vector<ll> &B) { return A[D] < B[D]; }

int make_tree(int depth, int l, int r) {
  if (l > r)
    return -1;
  D = depth % K;
  sort(P.begin() + l, P.begin() + r + 1, compare);
  int m = (l + r) / 2, res = G.size();
  G.push_back(node(P[m]));

  int vl = make_tree(depth + 1, l, m - 1);
  int vr = make_tree(depth + 1, m + 1, r);

  G[res].l = vl;
  G[res].r = vr;
  return res;
}

vector<int>
    num; // searchテ」ツ?ァティツヲツ凝」ツ?、テ」ツ?妥」ツつ凝」ツ?禿」ツ?ィテ」ツ?古」ツ?ァテ」ツ?催」ツ?淌ァツつケテ」ツ?ョnumberテ」ツつ津」ツ??」ツつ古」ツつ?

void search(int x, int depth, vector<ll> &L, vector<ll> &R) {
  bool f = true;
  for (int i = 0; i < K; i++)
    if (G[x].Point[i] < L[i] || R[i] < G[x].Point[i])
      f = false;

  if (f)
    num.push_back(G[x].Point[K]);

  D = depth % K;
  if (G[x].Point[D] <= R[D] && G[x].r != -1)
    search(G[x].r, depth + 1, L, R);
  D = depth % K;
  if (L[D] <= G[x].Point[D] && G[x].l != -1)
    search(G[x].l, depth + 1, L, R);
}

int main() {

  cin >> N >> R;

  P.resize(N);

  for (int i = 0; i < N; i++) {

    scanf("%lf %lf", &x[i], &y[i]);

    P[i].resize(K + 1);

    P[i][K] = i;
    P[i][0] = x[i], P[i][1] = y[i];
  }

  make_tree(0, 0, P.size() - 1);

  int ans = 0;
  for (int i = 0; i < N; i++) {

    if (used[i])
      continue;

    vector<ll> L2(K), R2(K);

    L2[0] = x[i] - R - EPS;
    R2[0] = x[i] + R + EPS;

    L2[1] = y[i] - R - EPS;
    R2[1] = y[i] + R + EPS;

    num.clear();

    search(0, 0, L2, R2);

    for (int j = 0; j < num.size(); j++)
      used[num[j]] = 1;

    ans++;
  }

  cout << ans << endl;

  return 0;
}