Submission #1043448

#TimeUsernameProblemLanguageResultExecution timeMemory
1043448vjudge1Circle selection (APIO18_circle_selection)C++17
19 / 100
839 ms61484 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 3e5 + 10; ll n, a[N][3], par[N]; ll dist(ll a, ll b, ll x, ll y){ return ((x - a) * (x - a) + (y - b) * (y - b)); } int main(){ cin >> n; for (ll i = 1; i <= n; i ++) for (ll j = 0; j < 3; j ++) cin >> a[i][j]; if (n <= 5000){ while (1){ ll mx = -1; for (ll i = 1; i <= n; i ++) if (!par[i] and (mx == -1 or a[i][2] > a[mx][2])) mx = i; if (mx == -1) break; for (ll i = 1; i <= n; i ++) if (!par[i] and dist(a[i][0], a[i][1], a[mx][0], a[mx][1]) <= (a[i][2] + a[mx][2]) * (a[i][2] + a[mx][2])) par[i] = mx; } for (ll i = 1; i <= n; i ++) cout << par[i] << " "; cout << endl; return 0; } set<pair<int, int>> st, rem; for (int i = 1; i <= n; i ++){ st.insert({a[i][0] + a[i][2], i}); st.insert({a[i][0] - a[i][2], i}); rem.insert({-a[i][2], i}); } while (rem.size()){ int c = (*rem.begin()).second; rem.erase(rem.begin()); if (par[c]) continue; auto it = st.lower_bound({a[c][0] + a[c][2], n}); while (it == st.end() or (*it).first > (a[c][0] + a[c][2])) it--; vector<int> done; while (1){ int i = (*it).second; if (dist(a[i][0], a[i][1], a[c][0], a[c][1]) <= (a[i][2] + a[c][2]) * (a[i][2] + a[c][2])){ par[i] = c; done.push_back(i); } else break; if (it == st.begin()) break; it--; } for (int i : done){ st.erase({a[i][0] + a[i][2], i}); st.erase({a[i][0] - a[i][2], i}); } } for (int i = 1; i <= n; i ++) cout << par[i] << " "; cout << endl; }
#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...