Submission #1292634

#TimeUsernameProblemLanguageResultExecution timeMemory
1292634Hamed_GhaffariCircle selection (APIO18_circle_selection)C++20
0 / 100
3095 ms25016 KiB
#include <bits/stdc++.h> using namespace std; #define int ll using ll = long long; using pii = pair<int, int>; #define X first #define Y second #define all(x) x.begin(), x.end() #define SZ(x) int(x.size()) const int MXN = 3e5+5; const int LOG = 31; struct circle { int x, y, r, id; }; bool isect(circle &c1, circle &c2) { ll x = c1.x - c2.x; ll y = c1.y - c2.y; return 1ll*(c1.r+c2.r)*(c1.r+c2.r) >= x*x + y*y; } struct { int t; vector<pii> cmp; vector<vector<circle>> vec; void add_(circle c) { cmp.push_back(pii(c.x/t, c.y/t)); } void build() { sort(all(cmp)); cmp.resize(unique(all(cmp))-cmp.begin()); vec.resize(SZ(cmp)); } int GI(pii x) { return lower_bound(all(cmp), x)-cmp.begin(); } void add(circle c) { vec[GI(pii(c.x/t, c.y/t))].push_back(c); } int find(circle &c) { for(auto x : vec) for(auto c2 : x) if(isect(c, c2)) return c2.id; // for(int i=c.x/t-2; i<=c.x/t+2; i++) { // int pos = GI(pii(i, c.y/t-2)); // while(pos<SZ(cmp) && cmp[pos].X==i && cmp[pos].Y<=c.y/t+2) { // for(auto &c2 : vec[pos]) // if(isect(c, c2)) // return c2.id; // pos++; // } // } return -1; } } ds[LOG]; int get_id(int r) { return 0; int l = __lg(r); if((1<<l)<r) l++; return l; } void init() { for(int i=0; i<LOG; i++) ds[i].t = 1<<i; } void add_(circle c) { ds[get_id(c.r)].add_(c); } void build() { for(int i=0; i<LOG; i++) ds[i].build(); } void add(circle c) { ds[get_id(c.r)].add(c); } int find(circle c) { for(int i=get_id(c.r); i<LOG; i++) { int tmp = ds[i].find(c); if(tmp!=-1) return tmp; } return -1; } int n, ans[MXN]; circle c[MXN]; int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; init(); for(int i=0; i<n; i++) { cin >> c[i].x >> c[i].y >> c[i].r; c[i].x += 1e9; c[i].id = i; add_(c[i]); } build(); sort(c, c+n, [&](circle &c1, circle &c2) { return c1.r > c2.r || (c1.r == c2.r && c1.id < c2.id); }); for(int i=0; i<n; i++) { // int tmp = find(c[i]); int tmp = -1; for(int j=0; j<i; j++) if(ans[c[j].id] == c[j].id && isect(c[j], c[i])) tmp = c[j].id; if(tmp==-1) { ans[c[i].id] = c[i].id; add(c[i]); } else ans[c[i].id] = tmp; } for(int i=0; i<n; i++) cout << ans[i]+1 << ' '; cout << '\n'; 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...