Submission #397548

#TimeUsernameProblemLanguageResultExecution timeMemory
397548AriaHCircle selection (APIO18_circle_selection)C++11
87 / 100
3094 ms396632 KiB
/* There's someone in my head but it's not me */ #include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define all(x) x.begin(), x.end() #define SZ(x) (int) x.size() #define F first #define S second #define lc id << 1 #define rc lc | 1 const int N = 3e5 + 4, MOD = 1e9 + 7; int n, X[N], Y[N], R[N], ord[N], ret[N], id[N]; ll base[N]; set<pii> seg[N << 1]; vector < pii > vec[N << 1]; vector <ll> cm; bool cmp(int i, int j) { if(R[i] == R[j]) return i < j; return R[i] > R[j]; } int intersect(int i, int j) { return (base[i] + base[j] + 2ll * (1ll * X[i] * X[j] + 1ll * Y[i] * Y[j] + 1ll * R[i] * R[j])) >= 0; } int lwr(ll x) { return lower_bound(all(cm), x) - cm.begin(); } void add(int pos, pii x) { pos += n; vec[pos].push_back(x); } void get(int ql, int qr, ll yl, ll yr, int p) { ql += n, qr += n + 1; while (qr - ql > 0) { if (ql & 1) { for (auto it = seg[ql].lower_bound({yl, -1e9}); it != seg[ql].end() && it->F <= yr; ) { auto x = *it; if (ret[x.S]) seg[ql].erase(x); else if (intersect(p, x.S)) ret[x.S] = p, seg[ql].erase(x); it = seg[ql].upper_bound(x); } ql++; } if (qr & 1) { qr--; for (auto it = seg[qr].lower_bound({yl, -1e9}); it != seg[qr].end() && it->F <= yr; ) { auto x = *it; if (ret[x.S]) seg[qr].erase(x); else if (intersect(p, x.S)) ret[x.S] = p, seg[qr].erase(x); it = seg[qr].upper_bound(x); } } qr >>= 1, ql >>= 1; } } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%d", &X[i], &Y[i], &R[i]), base[i] = 1ll * R[i] * R[i] - 1ll * X[i] * X[i] - 1ll * Y[i] * Y[i], cm.push_back(X[i]), ord[i] = i; sort(ord + 1, ord + n + 1, cmp); sort(all(cm)); cm.resize(unique(all(cm)) - cm.begin()); for(int i = 1; i <= n; i ++) { int I = ord[i]; ///printf("i = %d I = %d X = %d\n", i, I, X[I]); add(lwr(X[I]) + 1, make_pair(Y[I], I)); } for(int i = 1; i <= 2 * n + 2; i ++) { sort(all(vec[i])); } for(int i = n; i >= 1; i --) { merge(all(vec[i << 1]), all(vec[i << 1 | 1]), back_inserter(vec[i])); } for(int i = 0; i <= 2 * n + 2; i ++) { seg[i] = set < pair < int , int > > (vec[i].begin(), vec[i].end()); } for (int _ = 1; _ <= n; _++) { int i = ord[_]; if (ret[i]) continue; get(lwr(X[i] - 2ll * R[i]) + 1, lwr(X[i] + 2ll * R[i] + 1), Y[i] - 2ll * R[i], Y[i] + 2ll * R[i], i); } 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:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
circle_selection.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |         scanf("%d%d%d", &X[i], &Y[i], &R[i]), base[i] = 1ll * R[i] * R[i] - 1ll * X[i] * X[i] - 1ll * Y[i] * Y[i], cm.push_back(X[i]), ord[i] = 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...