Submission #49099

#TimeUsernameProblemLanguageResultExecution timeMemory
49099BTheroCircle selection (APIO18_circle_selection)C++17
0 / 100
420 ms26760 KiB
// Why am I so stupid? :c #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define fi first #define se second typedef long long ll; using namespace std; const int MAXN = 3e5+5; struct circle { int x, y, r, id; int L, R; circle() { x = y = r = id = 0; } } arr[MAXN]; bool col[MAXN << 2]; int t[MAXN << 2]; int ans[MAXN]; int n, m; void compress() { vector <int> vv; for (int i = 1; i <= n; ++i) { vv.pb(arr[i].x - arr[i].r); vv.pb(arr[i].x + arr[i].r); } sort(all(vv)); vv.resize(unique(all(vv)) - vv.begin()); m = vv.size(); for (int i = 1; i <= n; ++i) { arr[i].L = upper_bound(all(vv), arr[i].x - arr[i].r) - vv.begin(); arr[i].R = upper_bound(all(vv), arr[i].x + arr[i].r) - vv.begin(); } } bool cmp(circle a, circle b) { if (a.r == b.r) { return a.id < b.id; } return a.r > b.r; } bool inter(circle a, circle b) { ll d = (a.x - b.x) * 1ll * (a.x - b.x) + (a.y - b.y) * 1ll * (a.y - b.y); return d <= (a.r + b.r) * 1ll * (a.r + b.r); } void push(int v, int tl, int tr) { if (col[v] && tl != tr) { if (!col[v + v]) { col[v + v] = 1; t[v + v] = t[v]; } if (!col[v + v + 1]) { col[v + v + 1] = 1; t[v + v + 1] = t[v]; } } } int segMin(int v, int tl, int tr, int l, int r) { push(v, tl, tr); if (l > r || tl > r || tr < l) { return MAXN; } if (l <= tl && tr <= r) { return t[v]; } int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); return min( segMin(c1, tl, mid, l, r), segMin(c2, mid + 1, tr, l, r) ); } void segUpd(int v, int tl, int tr, int l, int r, int x) { push(v, tl, tr); if (l > r || tl > r || tr < l) { return; } if (l <= tl && tr <= r && !col[v]) { col[v] = 1; t[v] = min(t[v], x); push(v, tl, tr); return; } int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); segUpd(c1, tl, mid, l, r, x); segUpd(c2, mid + 1, tr, l, r, x); t[v] = min(t[c1], t[c2]); col[v] = (col[c1] & col[c2]); } void solve() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r); arr[i].id = i; } compress(); sort(arr + 1, arr + n + 1, cmp); for (int i = 1; i <= (m << 2); ++i) { t[i] = MAXN; } for (int i = 1; i <= n; ++i) { int cur = segMin(1, 1, m, arr[i].L, arr[i].R); if (cur <= n) { ans[arr[i].id] = arr[cur].id; } else { ans[arr[i].id] = arr[i].id; segUpd(1, 1, m, arr[i].L, arr[i].R, i); } } for (int i = 1; i <= n; ++i) { printf("%d ", ans[i]); } } int main() { #ifdef BThero freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // BThero int tt = 1; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

circle_selection.cpp: In function 'void solve()':
circle_selection.cpp:126:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
circle_selection.cpp:129:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...