Submission #397216

#TimeUsernameProblemLanguageResultExecution timeMemory
397216parsabahramiCircle selection (APIO18_circle_selection)C++17
7 / 100
3093 ms327040 KiB
/* There's someone in my head but it's not me */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 3e5 + 10, MOD = 1e9 + 7; int n, X[N], Y[N], R[N], ord[N], xord[N], pos[N], ret[N]; struct node : set<pii> { node *lc, *rc; node() : lc(nullptr), rc(nullptr) {} void build(int l = 1, int r = n + 1) { if (r - l < 2) return; int md = (l + r) >> 1; lc = new node(), rc = new node(); lc->build(l, md), rc->build(md, r); } void remove(int p, int id, int l = 1, int r = n + 1) { this->erase({Y[id], id}); if (r - l < 2) return; int md = (l + r) >> 1; if (p < md) lc->remove(p, id, l, md); else rc->remove(p, id, md, r); } int get(ll xl, ll xr, ll yl, ll yr, int l = 1, int r = n + 1) { if (xr <= X[xord[l]] || X[xord[r - 1]] + 1 <= xl || this->empty()) return -1; if (xl <= X[xord[l]] && X[xord[r - 1]] + 1 <= xr) { auto lb = this->lower_bound({yl, -1e9}); if (lb != this->end() && lb->F <= yr) return lb->S; else return -1; } int md = (l + r) >> 1, a; a = lc->get(xl, xr, yl, yr, l, md); if (~a) return a; return rc->get(xl, xr, yl, yr, md, r); } void ins(int p, int y, int id, int l = 1, int r = n + 1) { this->insert({y, id}); if (r - l < 2) return; int md = (l + r) >> 1; if (p < md) lc->ins(p, y, id, l, md); else rc->ins(p, y, id, md, r); } }; node* seg; int intersect(int i, int j) { ll x1 = X[i], x2 = X[j], y1 = Y[i], y2 = Y[j], r1 = R[i], r2 = R[j]; return x1 * x1 + x2 * x2 + y1 * y1 + y2 * y2 - r1 * r1 - r2 * r2 <= 2 * (r1 * r2 + x1 * x2 + y1 * y2); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%d", &X[i], &Y[i], &R[i]); iota(ord + 1, ord + n + 1, 1); iota(xord + 1, xord + n + 1, 1); sort(ord + 1, ord + n + 1, [&] (int i, int j) { return R[i] == R[j] ? i < j : R[i] > R[j]; }); sort(xord + 1, xord + n + 1, [&] (int i, int j) { return X[i] < X[j]; }); seg = new node(); seg->build(); for (int i = 1; i <= n; i++) { seg->ins(i, Y[xord[i]], xord[i]), pos[xord[i]] = i; } for (int _ = 1; _ <= n; _++) { int i = ord[_]; vector<int> ids; if (ret[i]) continue; for (;;) { int id = seg->get(X[i] - 2ll * R[i], X[i] + 2ll * R[i] + 1, Y[i] - 2ll * R[i], Y[i] + 2ll * R[i]); if (~id) ids.push_back(id), seg->remove(pos[id], id); else break; } for (int &id : ids) { if (intersect(i, id)) ret[id] = i; else seg->ins(pos[id], Y[id], id); } } for (int i = 1; i <= n; i++) printf("%d ", ret[i]); printf("\n"); return 0; }

Compilation message (stderr)

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
circle_selection.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |         scanf("%d%d%d", &X[i], &Y[i], &R[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...