Submission #710041

#TimeUsernameProblemLanguageResultExecution timeMemory
710041vjudge1Circle selection (APIO18_circle_selection)C++17
12 / 100
1805 ms72848 KiB
/* Author : DeMen100ns (a.k.a Vo Khac Trieu) School : VNU-HCM High school for the Gifted fuck you adhoc */ #include <bits/stdc++.h> #define endl '\n' #define int long long using namespace std; template<typename T> int SIZE(T (&t)){ return t.size(); } template<typename T, size_t N> int SIZE(T (&t)[N]){ return N; } string to_string(char t){ return "'" + string({t}) + "'"; } string to_string(bool t){ return t ? "true" : "false"; } string to_string(const string &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += t[i]; } return '"' + ret + '"'; } string to_string(const char* t){ string ret(t); return to_string(ret); } template<size_t N> string to_string(const bitset<N> &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){ ret += t[i] + '0'; } return to_string(ret); } template<typename T, typename... Coords> string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C); template<typename T, typename S> string to_string(const pair<T, S> &t){ return "(" + to_string(t.first) + ", " + to_string(t.second) + ")"; } template<typename T, typename... Coords> string to_string(const T (&t), int x1, int x2, Coords... C){ string ret = "["; x1 = min(x1, SIZE(t)); auto e = begin(t); advance(e,x1); for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += to_string(*e, C...) + (i != _i ? ", " : ""); e = next(e); } return ret + "]"; } template<int Index, typename... Ts> struct print_tuple{ string operator() (const tuple<Ts...>& t) { string ret = print_tuple<Index - 1, Ts...>{}(t); ret += (Index ? ", " : ""); return ret + to_string(get<Index>(t)); } }; template<typename... Ts> struct print_tuple<0, Ts...> { string operator() (const tuple<Ts...>& t) { return to_string(get<0>(t)); } }; template<typename... Ts> string to_string(const tuple<Ts...>& t) { const auto Size = tuple_size<tuple<Ts...>>::value; return print_tuple<Size - 1, Ts...>{}(t); } void dbgr(){;} template<typename Heads, typename... Tails> void dbgr(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgr(T...); } void dbgs(){;} template<typename Heads, typename... Tails> void dbgs(Heads H, Tails... T){ cout << H << " "; dbgs(T...); } #define dbgv(...) cout << to_string(__VA_ARGS__) << endl; #define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__); #define dbgr(...) dbgr(__VA_ARGS__); cout << endl; #define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__); const int N = 3e5 + 5; const long long INF = 1e18 + 7; const int MAXA = 1e9; const int B = sqrt(N) + 5; array<int, 3> a[N]; set <array<int, 3>> s; set <array<int, 3>> sl, sr; int ans[N]; bool f[N]; int dist(pair<int, int> a, pair<int, int> b){ int h1 = a.first - b.first; int h2 = a.second - b.second; return h1 * h1 + h2 * h2; } bool isintersect(array<int, 3> a, array<int, 3> b){ pair<int, int> a1 = {a[0], a[1]}; pair<int, int> b1 = {b[0], b[1]}; return dist(a1, b1) <= (a[2] + b[2]) * (a[2] + b[2]); } inline void erase(int id, int id2){ int x = a[id][0], r = a[id][1]; if (s.find({-r, r, id}) == s.end()) return; s.erase({-r, r, id}); sl.erase({x - r, x + r, id}); sr.erase({x + r, x - r, id}); ans[id] = id2; } void solve() { int n; cin >> n; for(int i = 1; i <= n; ++i){ int x, y, r; cin >> x >> y >> r; a[i] = {x, r, i}; s.insert({-r, r, i}); sl.insert({x - r, x + r, i}); sr.insert({x + r, x - r, i}); } while (!s.empty()){ array<int, 3> state = *s.begin(); int id = state[2]; int x = a[id][0], r = a[id][1]; int L = x - r, R = x + r; erase(id, id); ans[id] = id; array<int, 3> boundl = {L, -INF, -INF}; auto it = sl.lower_bound(boundl); vector <int> er; while (it != sl.end()){ if ((*it)[0] > R) break; er.push_back({(*it)[2]}); ++it; } auto it2 = sr.lower_bound(boundl); while (it2 != sr.end()){ if ((*it2)[0] > R) break; er.push_back({(*it2)[2]}); ++it2; } for(int i : er) erase(i, id); er.clear(); //dbg(s); } for(int i = 1; i <= n; ++i) cout << ans[i] << " "; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("codeforces.inp","r",stdin); // freopen("codeforces.out","w",stdout); int t = 1; // cin >> t; while (t--) { solve(); } }
#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...