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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| #include <iostream> #include <algorithm> #include <cstring> #include <set> using namespace std;
typedef long long ll;
const int N = 4e5 + 7;
struct operation{ int op; ll l, r; }a[N];
struct Sgt{ int l,r; set<int> id; #define l(u) tr[u].l #define r(u) tr[u].r #define ls u<<1 #define rs u<<1|1 }tr[N<<2];
void build(int u,int l,int r) { l(u) = l, r(u) = r; if (l == r) return; int mid = l + r >> 1; build(ls, l, mid), build(rs, mid + 1, r); }
void change(int u,int l,int r,int idx) { if (l(u) == l && r(u) == r) { tr[u].id.insert(idx); return; } int mid = l(u) + r(u) >> 1; if (r <= mid) change(ls, l, r, idx); else if (l > mid) change(rs, l, r, idx); else change(ls, l, mid, idx), change(rs, mid + 1, r, idx); }
int ask(int u,int p,int idx) { for (auto it : tr[u].id) { ll y = a[it].r; ll dx = a[idx].l - a[it].l, dy = a[idx].r - a[it].r; if (dx *dx + dy * dy < y * y) return it; } if (l(u) == r(u)) return -1; int mid = l(u) + r(u) >> 1; if (p <= mid) return ask(ls, p, idx); else return ask(rs, p, idx); }
void del(int u,int l,int r ,int idx) { if (l(u) == l && r(u) == r ) { tr[u].id.erase(idx); return; } int mid = l(u) + r(u) >> 1; if (r <= mid) del(ls, l, r, idx); else if (l > mid) del(rs, l, r, idx); else del(ls, l, mid, idx), del(rs, mid + 1, r, idx); }
int n,tot; ll b[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i ++ ) { scanf("%d%lld%lld", &a[i].op,&a[i].l, &a[i].r); if (a[i].op == 1) b[++tot] = a[i].l - a[i].r, b[++tot] = a[i].l + a[i].r; else b[++tot] = a[i].l; } sort(b + 1, b + 1 + tot); tot = unique(b + 1, b + 1 + tot) - (b + 1); build(1, 1, tot); for (int i = 1; i <= n; i ++ ) { if (a[i].op == 1) { int l = lower_bound(b + 1, b + 1 + tot, a[i].l - a[i].r) - b; int r = lower_bound(b + 1, b + 1 + tot, a[i].l + a[i].r) - b; change(1, l, r, i); } else { int po = lower_bound(b + 1, b + 1 + tot, a[i].l) - b; int ans = ask(1, po, i); printf("%d\n",ans); if (ans != -1) { int l = lower_bound(b + 1, b + 1 + tot, a[ans].l - a[ans].r) - b; int r = lower_bound(b + 1, b + 1 + tot, a[ans].l + a[ans].r) - b; del(1, l, r, ans); } } } return 0; }
|