Submission #966674

#TimeUsernameProblemLanguageResultExecution timeMemory
966674Soumya1Circle selection (APIO18_circle_selection)C++17
72 / 100
3022 ms198372 KiB
#include <bits/stdc++.h>
using namespace std;
const int mxN = 3e5 + 5;
int x[mxN], y[mxN], r[mxN], pos[mxN], ans[mxN];
set<pair<int, int>> st[2 * 4 * mxN];
int base;
void upd(int p, int q, int i) {
  p += base; q += base;
  p--; q--;
  while (p <= q) {
    if (p & 1) st[p++].insert({y[i], i});
    if (~q & 1) st[q--].insert({y[i], i});
    p >>= 1; q >>= 1;
  }
}
void update(int a, int b) {
  if (pos[b] < pos[ans[a]] && 1LL * (x[a] - x[b]) * (x[a] - x[b]) + 1LL * (y[a] - y[b]) * (y[a] - y[b]) <= 1LL * (r[a] + r[b]) * (r[a] + r[b]))
    ans[a] = b;
}
void check(int x, int i) {
  auto it = lower_bound(st[x].begin(), st[x].end(), pair<int, int> {y[i], -2e9});
  if (it != st[x].end()) {
    update(i, (*it).second);
    it++;
    if (it != st[x].end()) {
      update(i, (*it).second);
    }
  }
  it = lower_bound(st[x].begin(), st[x].end(), pair<int, int> {y[i], -2e9});
  if (it != st[x].begin()) {
    it--;
    update(i, (*it).second);
    if (it != st[x].begin()) {
      it--;
      update(i, (*it).second);
    }
  }
}
void get(int p, int i) {
  p += base; p--;
  while (p >= 1) {
    check(p, i);
    p >>= 1;
  }
}
// void update(int x, int lx, int rx, int l, int r, int i) {
//   if (l > rx || lx > r) return;
//   if (l <= lx && r >= rx) {
//     st[x].insert({y[i], i});
//     return;
//   }
//   int mx = (lx + rx) >> 1;
//   update(x << 1, lx, mx, l, r, i);
//   update(x << 1 | 1, mx + 1, rx, l, r, i);
// }
// void query(int x, int lx, int rx, int p, int i) {
//   check(x, i);
//   if (lx == rx) return;
//   int mx = (lx + rx) >> 1;
//   if (p <= mx) query(x << 1, lx, mx, p, i);
//   else query(x << 1 | 1, mx + 1, rx, p, i);
// }
void testCase() {
  int n;
  cin >> n;
  vector<int> all;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> r[i];
    all.push_back(x[i] - r[i]);
    all.push_back(x[i] + r[i]); 
  }
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    if (r[i] != r[j]) return r[i] > r[j];
    return i < j;
  });
  for (int i = 0; i < n; i++) {
    pos[ord[i]] = i;
  }
  sort(all.begin(), all.end());
  all.erase(unique(all.begin(), all.end()), all.end());
  int N = all.size();
  for (base = 1; base < N; base <<= 1);
  for (int i = 0; i < n; i++) ans[i] = i;
  for (int i = 0; i < n; i++) {
    int ii = ord[i];
    int L = lower_bound(all.begin(), all.end(), x[ii] - r[ii]) - all.begin() + 1;
    int R = lower_bound(all.begin(), all.end(), x[ii] + r[ii]) - all.begin() + 1;
    get(L, ii);
    get(R, ii);
    if (ans[ii] == ii) {
      upd(L, R, ii);
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i] + 1 << " ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...