#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
typedef complex<int> pt;
#define X real()
#define Y imag()
auto cross(pt u, pt v) {return (ll)u.X*v.Y-(ll)u.Y*v.X;}
auto sgn(ll a) {return a==0?0:(a>0?1:-1);}
auto ccw(pt p1, pt p2, pt p3) {auto u = p2-p1, v = p3-p2;return cross(u,v);}
auto in(pt p1, pt p2) {return (ll)p1.X*p2.X+(ll)p1.Y*p2.Y;}
auto norm(pt p) {return (ll)p.X*p.X+(ll)p.Y*p.Y;}
bool comp(const pt& a, const pt& b) { return a.X<b.X or (a.X==b.X and a.Y < b.Y);}
void read(pt& p) {
int a,b; cin >> a >> b;
p = {a,b};
}
vi ans;
vector<pt> pts;
vi r;
struct cmp {
bool operator()(int i, int j) const {
return make_pair(pts[i].Y,i)<make_pair(pts[j].Y,j);
}
};
bool xcomp(int i, int j) {
return pts[i].X<pts[j].X;
}
bool rcomp(int i, int j) {
return make_pair(-r[i],i)<make_pair(-r[j],j);
}
bool intersect(int i, int j) {
return norm(pts[i]-pts[j])<=ll(r[i]+r[j])*(r[i]+r[j]);
}
vi rec(vi ord) {
int n = ord.size();
if(n<=1) {
return ord;
}
int mid = n/2;
auto kill = rec({ord.begin(),ord.begin()+mid});
int rmid = r[ord[mid]];
vi oord = ord;
oord.erase(oord.begin(),oord.begin()+mid);
for(int rep=0;rep<2;++rep) {
sort(all(oord),xcomp);
sort(all(kill),xcomp);
multiset<int,cmp> s;
int j=0;
for(int i : oord) {
while(j<(int)kill.size() and !xcomp(i,kill[j])) {
s.insert(kill[j++]);
}
auto it = s.lower_bound(i);
pt q = pts[i];
while(it!=s.end()) {
// consider this
pt p = pts[*it];
if(intersect(*it,i)) {
ans[i]=min(ans[i],*it,rcomp);
}
if(q.X-p.X>rmid+r[*it]) {
it = s.erase(it);
} else if(q.X-p.X<abs(p.Y-q.Y)) {
break;
} else ++it;
}
it = s.lower_bound(i);
while(it!=s.begin()) {
--it;
pt p = pts[*it];
if(intersect(*it,i)) {
ans[i]=min(ans[i],*it,rcomp);
}
if(q.X-p.X>rmid+r[*it]) {
it = s.erase(it);
} else if(q.X-p.X<abs(p.Y-q.Y)) {
break;
}
}
}
for(auto& i : ord) pts[i] = {-pts[i].X,pts[i].Y};
}
oord.erase(partition(all(oord),[&](int i) {return ans[i]==i;}),oord.end());
sort(all(oord),rcomp);
auto kill2 = rec(oord);
kill.insert(kill.begin(),all(kill2));
return kill;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
ans.resize(n),r.resize(n),pts.resize(n);
iota(all(ans),0);
for(int i=0;i<n;++i) read(pts[i]),cin >> r[i];
vi ord = ans;
sort(all(ord),rcomp);
rec(ord);
for(auto& i : ans) ++i;
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
232 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
352 KB |
Output is correct |
19 |
Correct |
4 ms |
552 KB |
Output is correct |
20 |
Correct |
5 ms |
596 KB |
Output is correct |
21 |
Correct |
4 ms |
556 KB |
Output is correct |
22 |
Correct |
20 ms |
636 KB |
Output is correct |
23 |
Correct |
18 ms |
624 KB |
Output is correct |
24 |
Correct |
15 ms |
724 KB |
Output is correct |
25 |
Correct |
22 ms |
620 KB |
Output is correct |
26 |
Correct |
22 ms |
628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
15472 KB |
Output is correct |
2 |
Correct |
299 ms |
15464 KB |
Output is correct |
3 |
Correct |
241 ms |
15396 KB |
Output is correct |
4 |
Correct |
244 ms |
15500 KB |
Output is correct |
5 |
Correct |
237 ms |
13440 KB |
Output is correct |
6 |
Correct |
576 ms |
14568 KB |
Output is correct |
7 |
Correct |
275 ms |
13608 KB |
Output is correct |
8 |
Correct |
311 ms |
13668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
490 ms |
7148 KB |
Output is correct |
3 |
Correct |
1622 ms |
22344 KB |
Output is correct |
4 |
Correct |
1612 ms |
20700 KB |
Output is correct |
5 |
Correct |
1320 ms |
19824 KB |
Output is correct |
6 |
Correct |
455 ms |
10004 KB |
Output is correct |
7 |
Correct |
216 ms |
5584 KB |
Output is correct |
8 |
Correct |
35 ms |
1548 KB |
Output is correct |
9 |
Correct |
1742 ms |
20708 KB |
Output is correct |
10 |
Correct |
1167 ms |
19016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1414 ms |
21108 KB |
Output is correct |
2 |
Correct |
1339 ms |
19380 KB |
Output is correct |
3 |
Correct |
399 ms |
17380 KB |
Output is correct |
4 |
Correct |
1248 ms |
19704 KB |
Output is correct |
5 |
Correct |
1301 ms |
20916 KB |
Output is correct |
6 |
Correct |
301 ms |
17296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
232 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
352 KB |
Output is correct |
19 |
Correct |
4 ms |
552 KB |
Output is correct |
20 |
Correct |
5 ms |
596 KB |
Output is correct |
21 |
Correct |
4 ms |
556 KB |
Output is correct |
22 |
Correct |
20 ms |
636 KB |
Output is correct |
23 |
Correct |
18 ms |
624 KB |
Output is correct |
24 |
Correct |
15 ms |
724 KB |
Output is correct |
25 |
Correct |
22 ms |
620 KB |
Output is correct |
26 |
Correct |
22 ms |
628 KB |
Output is correct |
27 |
Correct |
7 ms |
1024 KB |
Output is correct |
28 |
Correct |
7 ms |
972 KB |
Output is correct |
29 |
Correct |
8 ms |
980 KB |
Output is correct |
30 |
Correct |
32 ms |
1068 KB |
Output is correct |
31 |
Correct |
35 ms |
1008 KB |
Output is correct |
32 |
Correct |
30 ms |
980 KB |
Output is correct |
33 |
Correct |
92 ms |
6460 KB |
Output is correct |
34 |
Correct |
75 ms |
6396 KB |
Output is correct |
35 |
Correct |
80 ms |
6224 KB |
Output is correct |
36 |
Correct |
410 ms |
7020 KB |
Output is correct |
37 |
Correct |
447 ms |
7044 KB |
Output is correct |
38 |
Correct |
442 ms |
7260 KB |
Output is correct |
39 |
Correct |
236 ms |
4732 KB |
Output is correct |
40 |
Correct |
230 ms |
4820 KB |
Output is correct |
41 |
Correct |
310 ms |
4720 KB |
Output is correct |
42 |
Correct |
166 ms |
5320 KB |
Output is correct |
43 |
Correct |
338 ms |
7088 KB |
Output is correct |
44 |
Correct |
322 ms |
6992 KB |
Output is correct |
45 |
Correct |
314 ms |
7224 KB |
Output is correct |
46 |
Correct |
312 ms |
7208 KB |
Output is correct |
47 |
Correct |
320 ms |
7144 KB |
Output is correct |
48 |
Correct |
346 ms |
7136 KB |
Output is correct |
49 |
Correct |
352 ms |
7108 KB |
Output is correct |
50 |
Correct |
319 ms |
7028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
232 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
352 KB |
Output is correct |
19 |
Correct |
4 ms |
552 KB |
Output is correct |
20 |
Correct |
5 ms |
596 KB |
Output is correct |
21 |
Correct |
4 ms |
556 KB |
Output is correct |
22 |
Correct |
20 ms |
636 KB |
Output is correct |
23 |
Correct |
18 ms |
624 KB |
Output is correct |
24 |
Correct |
15 ms |
724 KB |
Output is correct |
25 |
Correct |
22 ms |
620 KB |
Output is correct |
26 |
Correct |
22 ms |
628 KB |
Output is correct |
27 |
Correct |
314 ms |
15472 KB |
Output is correct |
28 |
Correct |
299 ms |
15464 KB |
Output is correct |
29 |
Correct |
241 ms |
15396 KB |
Output is correct |
30 |
Correct |
244 ms |
15500 KB |
Output is correct |
31 |
Correct |
237 ms |
13440 KB |
Output is correct |
32 |
Correct |
576 ms |
14568 KB |
Output is correct |
33 |
Correct |
275 ms |
13608 KB |
Output is correct |
34 |
Correct |
311 ms |
13668 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
490 ms |
7148 KB |
Output is correct |
37 |
Correct |
1622 ms |
22344 KB |
Output is correct |
38 |
Correct |
1612 ms |
20700 KB |
Output is correct |
39 |
Correct |
1320 ms |
19824 KB |
Output is correct |
40 |
Correct |
455 ms |
10004 KB |
Output is correct |
41 |
Correct |
216 ms |
5584 KB |
Output is correct |
42 |
Correct |
35 ms |
1548 KB |
Output is correct |
43 |
Correct |
1742 ms |
20708 KB |
Output is correct |
44 |
Correct |
1167 ms |
19016 KB |
Output is correct |
45 |
Correct |
1414 ms |
21108 KB |
Output is correct |
46 |
Correct |
1339 ms |
19380 KB |
Output is correct |
47 |
Correct |
399 ms |
17380 KB |
Output is correct |
48 |
Correct |
1248 ms |
19704 KB |
Output is correct |
49 |
Correct |
1301 ms |
20916 KB |
Output is correct |
50 |
Correct |
301 ms |
17296 KB |
Output is correct |
51 |
Correct |
7 ms |
1024 KB |
Output is correct |
52 |
Correct |
7 ms |
972 KB |
Output is correct |
53 |
Correct |
8 ms |
980 KB |
Output is correct |
54 |
Correct |
32 ms |
1068 KB |
Output is correct |
55 |
Correct |
35 ms |
1008 KB |
Output is correct |
56 |
Correct |
30 ms |
980 KB |
Output is correct |
57 |
Correct |
92 ms |
6460 KB |
Output is correct |
58 |
Correct |
75 ms |
6396 KB |
Output is correct |
59 |
Correct |
80 ms |
6224 KB |
Output is correct |
60 |
Correct |
410 ms |
7020 KB |
Output is correct |
61 |
Correct |
447 ms |
7044 KB |
Output is correct |
62 |
Correct |
442 ms |
7260 KB |
Output is correct |
63 |
Correct |
236 ms |
4732 KB |
Output is correct |
64 |
Correct |
230 ms |
4820 KB |
Output is correct |
65 |
Correct |
310 ms |
4720 KB |
Output is correct |
66 |
Correct |
166 ms |
5320 KB |
Output is correct |
67 |
Correct |
338 ms |
7088 KB |
Output is correct |
68 |
Correct |
322 ms |
6992 KB |
Output is correct |
69 |
Correct |
314 ms |
7224 KB |
Output is correct |
70 |
Correct |
312 ms |
7208 KB |
Output is correct |
71 |
Correct |
320 ms |
7144 KB |
Output is correct |
72 |
Correct |
346 ms |
7136 KB |
Output is correct |
73 |
Correct |
352 ms |
7108 KB |
Output is correct |
74 |
Correct |
319 ms |
7028 KB |
Output is correct |
75 |
Correct |
284 ms |
18072 KB |
Output is correct |
76 |
Correct |
253 ms |
17512 KB |
Output is correct |
77 |
Correct |
297 ms |
17688 KB |
Output is correct |
78 |
Correct |
259 ms |
17788 KB |
Output is correct |
79 |
Correct |
338 ms |
17464 KB |
Output is correct |
80 |
Correct |
266 ms |
17892 KB |
Output is correct |
81 |
Correct |
1741 ms |
20528 KB |
Output is correct |
82 |
Correct |
1748 ms |
20288 KB |
Output is correct |
83 |
Correct |
1577 ms |
20628 KB |
Output is correct |
84 |
Correct |
1667 ms |
20796 KB |
Output is correct |
85 |
Correct |
1474 ms |
21408 KB |
Output is correct |
86 |
Correct |
1494 ms |
21644 KB |
Output is correct |
87 |
Correct |
1957 ms |
20528 KB |
Output is correct |
88 |
Correct |
730 ms |
13272 KB |
Output is correct |
89 |
Correct |
835 ms |
13300 KB |
Output is correct |
90 |
Correct |
723 ms |
13100 KB |
Output is correct |
91 |
Correct |
741 ms |
13272 KB |
Output is correct |
92 |
Correct |
725 ms |
13124 KB |
Output is correct |
93 |
Correct |
1314 ms |
19376 KB |
Output is correct |
94 |
Correct |
2872 ms |
23460 KB |
Output is correct |
95 |
Correct |
1259 ms |
19440 KB |
Output is correct |
96 |
Correct |
1231 ms |
19664 KB |
Output is correct |
97 |
Correct |
2189 ms |
19488 KB |
Output is correct |
98 |
Correct |
629 ms |
17548 KB |
Output is correct |
99 |
Correct |
1217 ms |
21140 KB |
Output is correct |
100 |
Correct |
1190 ms |
19456 KB |
Output is correct |
101 |
Correct |
750 ms |
18144 KB |
Output is correct |
102 |
Correct |
1171 ms |
19416 KB |
Output is correct |
103 |
Correct |
2660 ms |
19800 KB |
Output is correct |
104 |
Correct |
1239 ms |
19544 KB |
Output is correct |
105 |
Correct |
465 ms |
14332 KB |
Output is correct |
106 |
Correct |
856 ms |
20404 KB |
Output is correct |
107 |
Correct |
849 ms |
19856 KB |
Output is correct |
108 |
Correct |
859 ms |
20432 KB |
Output is correct |
109 |
Correct |
866 ms |
19776 KB |
Output is correct |
110 |
Correct |
859 ms |
19520 KB |
Output is correct |
111 |
Correct |
855 ms |
20540 KB |
Output is correct |
112 |
Correct |
852 ms |
20676 KB |
Output is correct |
113 |
Correct |
853 ms |
19400 KB |
Output is correct |
114 |
Correct |
864 ms |
19752 KB |
Output is correct |
115 |
Correct |
853 ms |
19812 KB |
Output is correct |
116 |
Correct |
848 ms |
20720 KB |
Output is correct |