1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 5e4 + 50; int n, r, l, cx, cy, fa[maxn], val[maxn]; bool vis[maxn];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void join(int x, int y) { int a = find(x), b = find(y); if (a == b) return; val[a] += val[b]; fa[b] = a; }
struct node1 { int x_, y_; bool operator<(node1 &x) { return x_ < x.x_; } } arr[maxn];
struct node2 { int y_, id_; node2(int y, int id) : y_(y), id_(id) {} bool operator<(const node2 &x) const { if (y_ != x.y_) return y_ < x.y_; return id_ < x.id_; } }; set<node2> st;
int main() { while (cin >> n >> r >> l) { l /= 2; st.clear(), memset(vis, 0, sizeof(vis)); for (int i = 1; i <= n; ++i) { cin >> arr[i].x_ >> arr[i].y_; fa[i] = i, val[i] = 1; } cin >> cx >> cy; sort(arr + 1, arr + 1 + n); int head = 1, tail = 1; while (head <= tail && tail <= n) { while (head <= tail && arr[tail].x_ - arr[head].x_ > l) { st.erase(node2(arr[head].y_, head)); ++head; } auto it = st.emplace(arr[tail].y_, tail).first; if (it != st.begin() && it->y_ - prev(it)->y_ <= l) { join(prev(it)->id_, it->id_); } if (next(it) != st.end() && next(it)->y_ - it->y_ <= l) { join(it->id_, next(it)->id_); } ++tail; } ll x, y, f, ans = 0; for (int i = 1; i <= n; ++i) { x = abs(arr[i].x_ - cx), y = abs(arr[i].y_ - cy); if (x * x + y * y <= 1ll * r * r) { f = find(i); if (!vis[f]) vis[f] = 1, ans += val[f]; } } cout << ans << endl; } return 0; }
|