제출 #50133

#제출 시각아이디문제언어결과실행 시간메모리
50133mirbek01원 고르기 (APIO18_circle_selection)C++17
0 / 100
1517 ms133216 KiB
# include <bits/stdc++.h> # define f first # define s second using namespace std; const int N = 3e5 + 2; struct st{ int x, y, r, id; } a[N]; struct node{ int l, r; pair <int, int> x; node(){ l = r = 0; x = {1e9, 1e9}; } }t[N * 4]; int n, fl = 1, ans[N], sz = 1; bool cmp(st a, st b){ if(a.r == b.r) return a.id < b.id; return a.r > b.r; } void update(int pos, pair <int, int> val, int v = 1, int tl = -1e9, int tr = 1e9){ if(tl == tr){ t[v].x = val; } else { int tm = (tl + tr) >> 1; if(pos <= tm){ if(!t[v].l) t[v].l = ++ sz; update(pos, val, t[v].l, tl, tm); } else { if(!t[v].r) t[v].r = ++ sz; update(pos, val, t[v].r, tm + 1, tr); } t[v].x = min(t[ t[v].l ].x, t[ t[v].r ].x); } } pair <int, int> get(int l, int r, int v = 1, int tl = -1e9, int tr = 1e9){ if(l > tr || tl > r || t[v].x.f == 1e9) return {1e9, 1e9}; if(l <= tl && tr <= r) return t[v].x; int tm = (tl + tr) >> 1; return min(get(l, r, t[v].l, tl, tm), get(l, r, t[v].r, tm + 1, tr)); } int main(){ cin >> n; for(int i = 1; i <= n; i ++){ cin >> a[i].x >> a[i].y >> a[i].r; a[i].id = i; if(a[i].y) fl = 0; } if(fl){ sort(a + 1, a + n + 1, cmp); set <int> st; for(int i = 1; i <= n; i ++){ st.insert(a[i].x); st.insert(a[i].x - a[i].r); st.insert(a[i].x + a[i].r); } for(int i = 1; i <= n; i ++){ vector <int> v; for(auto j = st.lower_bound(a[i].x - a[i].r); j != st.end() && *j <= a[i].x + a[i].r; j ++){ update(*j, {-a[i].r, a[i].id}); v.push_back(*j); } while(!v.empty()){ st.erase(v.back()); v.pop_back(); } ans[a[i].id] = get(a[i].x - a[i].r, a[i].x + a[i].r).s; } for(int i = 1; i <= n; i ++){ cout << ans[i] << " "; } } } /** 3 1 0 5 9 0 4 3 0 3 11 9 9 2 13 2 1 11 8 2 3 3 2 3 12 1 12 14 1 9 8 5 2 8 2 5 2 1 14 4 2 14 14 1 **/
#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...