#include <bits/stdc++.h>
using namespace std;
#define y1 ___y1
typedef long long ll;
typedef pair<ll, ll> pll;
const int inf = 1e9 + 333;
const ll linf = 1e18 + 333;
const int N = 3e5 + 5;
class tree {
public:
ll x, y, x1, y1, x2, y2;
int idx;
int alive, sum;
tree *l, *r;
tree() {
x = y = x1 = y1 = x2 = y2 = idx = -1;
alive = sum = 0;
l = r = 0;
}
};
typedef tree *pTree;
int n, sz, type;
ll x1, y1, x2, y2;
ll k;
map<pll, int> h;
map<pll, ll> M;
pair<pll, int> a[N];
bool cmp(pair<pll, int> x, pair<pll, int> y) {
if (x.first.second == y.first.second)
return x.first.first < y.first.first;
return x.first.second < y.first.second;
}
void init(pTree t, int l, int r, bool d = 0) {
// printf("l = %d r = %d\n", l, r);
int m = (l + r) >> 1;
if (!d)
nth_element(a + l, a + m, a + r + 1);
else
nth_element(a + l, a + m, a + r + 1, cmp);
// puts("ASD");
t->x = t->x1 = t->x2 = a[m].first.first;
t->y = t->y1 = t->y2 = a[m].first.second;
t->idx = a[m].second;
t->alive = t->sum = 1;
if (l < m) {
if (!t->l)
t->l = new tree;
init(t->l, l, m - 1, !d);
t->sum += t->l->sum;
t->x1 = min(t->x1, t->l->x1);
t->y1 = min(t->y1, t->l->y1);
t->x2 = max(t->x2, t->l->x2);
t->y2 = max(t->y2, t->l->y2);
}
if (m < r) {
if (!t->r)
t->r = new tree;
init(t->r, m + 1, r, !d);
t->sum += t->r->sum;
t->x1 = min(t->x1, t->r->x1);
t->y1 = min(t->y1, t->r->y1);
t->x2 = max(t->x2, t->r->x2);
t->y2 = max(t->y2, t->r->y2);
}
}
ll X[N], Y[N], R[N];
int ord[N], ans[N];
bool check_intersection(ll x1, ll y1, ll r1, ll x2, ll y2, ll r2) {
return (ll) (x1 - x2) * (x1 - x2) + (ll) (y1 - y2) * (y1 - y2) <= (ll) (r1 + r2) * (r1 + r2);
}
ll ox, oy, o_r;
int oid;
void query(pTree t) {
if (x2 < t->x1 or t->x2 < x1 or y2 < t->y1 or t->y2 < y1)
return;
// if (x1 <= t->x1 and t->x2 <= x2 and y1 <= t->y1 and t->y2 <= y2)
// return t->ans;
if(t->alive and check_intersection(ox, oy, o_r, X[t->idx], Y[t->idx], R[t->idx])) {
ans[t->idx] = oid;
t->alive = 0;
}
if (t->l)
query(t->l);
if (t->r)
query(t->r);
t->sum = (t->l?t->l->sum:0) + (t->r?t->r->sum:0) + t->alive;
}
// void change(pTree t, bool d = 0) {
// if (x1 == t->x and y1 == t->y) {
// t->val = t->ans = k;
// if (t->l)
// t->ans = gcd(t->ans, t->l->ans);
// if (t->r)
// t->ans = gcd(t->ans, t->r->ans);
// return;
// }
// if ((!d and pll(x1, y1) < pll(t->x, t->y)) or (d and pll(y1, x1) < pll(t->y, t->x)))
// change(t->l, !d);
// else
// change(t->r, !d);
// t->ans = t->val;
// if (t->l)
// t->ans = gcd(t->ans, t->l->ans);
// if (t->r)
// t->ans = gcd(t->ans, t->r->ans);
// }
pTree t;
void calculate(ll x, ll y, ll r, int id) {
::x1 = x - 2 * r;
::y1 = y - 2 * r;
::x2 = x + 2 * r;
::y2 = y + 2 * r;
ox = x;
oy = y;
o_r = r;
oid = id;
query(t);
}
int main() {
memset(ans, -1, sizeof(ans));
t = new tree;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%lld %lld %lld", X + i, Y + i, R + i);
ord[i] = i;
a[i] = {{X[i], Y[i]}, i};
}
sort(ord, ord + n, [&](int x, int y){
if(R[x] != R[y]) {
return R[x] > R[y];
}
return x < y;
});
// puts("ASD");
init(t, 0, n - 1);
// puts("BSD");
for(int i = 0; i < n; i++) {
ll x = X[ord[i]];
ll y = Y[ord[i]];
ll r = R[ord[i]];
if(ans[ord[i]] != -1) {
continue;
}
ans[ord[i]] = ord[i];
calculate(x, y, r, ord[i]);
}
for(int i = 0; i < n; i++) {
printf("%d ", ans[i] + 1);
}
puts("");
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:162:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
162 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:165:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
165 | scanf("%lld %lld %lld", X + i, Y + i, R + i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1480 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
2 ms |
1620 KB |
Output is correct |
17 |
Correct |
1 ms |
1620 KB |
Output is correct |
18 |
Correct |
1 ms |
1692 KB |
Output is correct |
19 |
Correct |
4 ms |
2408 KB |
Output is correct |
20 |
Correct |
4 ms |
2388 KB |
Output is correct |
21 |
Correct |
4 ms |
2384 KB |
Output is correct |
22 |
Correct |
6 ms |
2292 KB |
Output is correct |
23 |
Correct |
5 ms |
2388 KB |
Output is correct |
24 |
Correct |
5 ms |
2284 KB |
Output is correct |
25 |
Correct |
5 ms |
2324 KB |
Output is correct |
26 |
Correct |
5 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
209 ms |
46912 KB |
Output is correct |
2 |
Correct |
210 ms |
46984 KB |
Output is correct |
3 |
Correct |
211 ms |
50920 KB |
Output is correct |
4 |
Correct |
214 ms |
51168 KB |
Output is correct |
5 |
Correct |
238 ms |
50912 KB |
Output is correct |
6 |
Correct |
279 ms |
51632 KB |
Output is correct |
7 |
Correct |
216 ms |
51584 KB |
Output is correct |
8 |
Correct |
224 ms |
51524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
113 ms |
16564 KB |
Output is correct |
3 |
Correct |
441 ms |
54924 KB |
Output is correct |
4 |
Correct |
436 ms |
55048 KB |
Output is correct |
5 |
Correct |
376 ms |
53644 KB |
Output is correct |
6 |
Correct |
152 ms |
29428 KB |
Output is correct |
7 |
Correct |
84 ms |
16036 KB |
Output is correct |
8 |
Correct |
13 ms |
4436 KB |
Output is correct |
9 |
Correct |
440 ms |
54956 KB |
Output is correct |
10 |
Correct |
354 ms |
55228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
364 ms |
46812 KB |
Output is correct |
2 |
Correct |
348 ms |
53964 KB |
Output is correct |
3 |
Correct |
242 ms |
54872 KB |
Output is correct |
4 |
Correct |
354 ms |
54252 KB |
Output is correct |
5 |
Correct |
351 ms |
54432 KB |
Output is correct |
6 |
Correct |
231 ms |
54712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1480 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
2 ms |
1620 KB |
Output is correct |
17 |
Correct |
1 ms |
1620 KB |
Output is correct |
18 |
Correct |
1 ms |
1692 KB |
Output is correct |
19 |
Correct |
4 ms |
2408 KB |
Output is correct |
20 |
Correct |
4 ms |
2388 KB |
Output is correct |
21 |
Correct |
4 ms |
2384 KB |
Output is correct |
22 |
Correct |
6 ms |
2292 KB |
Output is correct |
23 |
Correct |
5 ms |
2388 KB |
Output is correct |
24 |
Correct |
5 ms |
2284 KB |
Output is correct |
25 |
Correct |
5 ms |
2324 KB |
Output is correct |
26 |
Correct |
5 ms |
2388 KB |
Output is correct |
27 |
Correct |
7 ms |
3292 KB |
Output is correct |
28 |
Correct |
7 ms |
3208 KB |
Output is correct |
29 |
Correct |
7 ms |
3284 KB |
Output is correct |
30 |
Correct |
12 ms |
3156 KB |
Output is correct |
31 |
Correct |
9 ms |
3160 KB |
Output is correct |
32 |
Correct |
9 ms |
3200 KB |
Output is correct |
33 |
Correct |
69 ms |
19652 KB |
Output is correct |
34 |
Correct |
69 ms |
19560 KB |
Output is correct |
35 |
Correct |
73 ms |
19416 KB |
Output is correct |
36 |
Correct |
112 ms |
19008 KB |
Output is correct |
37 |
Correct |
113 ms |
19164 KB |
Output is correct |
38 |
Correct |
119 ms |
19164 KB |
Output is correct |
39 |
Correct |
146 ms |
17572 KB |
Output is correct |
40 |
Correct |
165 ms |
17612 KB |
Output is correct |
41 |
Correct |
156 ms |
17520 KB |
Output is correct |
42 |
Correct |
71 ms |
17996 KB |
Output is correct |
43 |
Correct |
89 ms |
19076 KB |
Output is correct |
44 |
Correct |
85 ms |
19048 KB |
Output is correct |
45 |
Correct |
89 ms |
19152 KB |
Output is correct |
46 |
Correct |
103 ms |
19056 KB |
Output is correct |
47 |
Correct |
84 ms |
19104 KB |
Output is correct |
48 |
Correct |
82 ms |
19104 KB |
Output is correct |
49 |
Correct |
83 ms |
19176 KB |
Output is correct |
50 |
Correct |
89 ms |
19060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1480 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
2 ms |
1620 KB |
Output is correct |
17 |
Correct |
1 ms |
1620 KB |
Output is correct |
18 |
Correct |
1 ms |
1692 KB |
Output is correct |
19 |
Correct |
4 ms |
2408 KB |
Output is correct |
20 |
Correct |
4 ms |
2388 KB |
Output is correct |
21 |
Correct |
4 ms |
2384 KB |
Output is correct |
22 |
Correct |
6 ms |
2292 KB |
Output is correct |
23 |
Correct |
5 ms |
2388 KB |
Output is correct |
24 |
Correct |
5 ms |
2284 KB |
Output is correct |
25 |
Correct |
5 ms |
2324 KB |
Output is correct |
26 |
Correct |
5 ms |
2388 KB |
Output is correct |
27 |
Correct |
209 ms |
46912 KB |
Output is correct |
28 |
Correct |
210 ms |
46984 KB |
Output is correct |
29 |
Correct |
211 ms |
50920 KB |
Output is correct |
30 |
Correct |
214 ms |
51168 KB |
Output is correct |
31 |
Correct |
238 ms |
50912 KB |
Output is correct |
32 |
Correct |
279 ms |
51632 KB |
Output is correct |
33 |
Correct |
216 ms |
51584 KB |
Output is correct |
34 |
Correct |
224 ms |
51524 KB |
Output is correct |
35 |
Correct |
1 ms |
1492 KB |
Output is correct |
36 |
Correct |
113 ms |
16564 KB |
Output is correct |
37 |
Correct |
441 ms |
54924 KB |
Output is correct |
38 |
Correct |
436 ms |
55048 KB |
Output is correct |
39 |
Correct |
376 ms |
53644 KB |
Output is correct |
40 |
Correct |
152 ms |
29428 KB |
Output is correct |
41 |
Correct |
84 ms |
16036 KB |
Output is correct |
42 |
Correct |
13 ms |
4436 KB |
Output is correct |
43 |
Correct |
440 ms |
54956 KB |
Output is correct |
44 |
Correct |
354 ms |
55228 KB |
Output is correct |
45 |
Correct |
364 ms |
46812 KB |
Output is correct |
46 |
Correct |
348 ms |
53964 KB |
Output is correct |
47 |
Correct |
242 ms |
54872 KB |
Output is correct |
48 |
Correct |
354 ms |
54252 KB |
Output is correct |
49 |
Correct |
351 ms |
54432 KB |
Output is correct |
50 |
Correct |
231 ms |
54712 KB |
Output is correct |
51 |
Correct |
7 ms |
3292 KB |
Output is correct |
52 |
Correct |
7 ms |
3208 KB |
Output is correct |
53 |
Correct |
7 ms |
3284 KB |
Output is correct |
54 |
Correct |
12 ms |
3156 KB |
Output is correct |
55 |
Correct |
9 ms |
3160 KB |
Output is correct |
56 |
Correct |
9 ms |
3200 KB |
Output is correct |
57 |
Correct |
69 ms |
19652 KB |
Output is correct |
58 |
Correct |
69 ms |
19560 KB |
Output is correct |
59 |
Correct |
73 ms |
19416 KB |
Output is correct |
60 |
Correct |
112 ms |
19008 KB |
Output is correct |
61 |
Correct |
113 ms |
19164 KB |
Output is correct |
62 |
Correct |
119 ms |
19164 KB |
Output is correct |
63 |
Correct |
146 ms |
17572 KB |
Output is correct |
64 |
Correct |
165 ms |
17612 KB |
Output is correct |
65 |
Correct |
156 ms |
17520 KB |
Output is correct |
66 |
Correct |
71 ms |
17996 KB |
Output is correct |
67 |
Correct |
89 ms |
19076 KB |
Output is correct |
68 |
Correct |
85 ms |
19048 KB |
Output is correct |
69 |
Correct |
89 ms |
19152 KB |
Output is correct |
70 |
Correct |
103 ms |
19056 KB |
Output is correct |
71 |
Correct |
84 ms |
19104 KB |
Output is correct |
72 |
Correct |
82 ms |
19104 KB |
Output is correct |
73 |
Correct |
83 ms |
19176 KB |
Output is correct |
74 |
Correct |
89 ms |
19060 KB |
Output is correct |
75 |
Correct |
228 ms |
55984 KB |
Output is correct |
76 |
Correct |
229 ms |
55708 KB |
Output is correct |
77 |
Correct |
252 ms |
55896 KB |
Output is correct |
78 |
Correct |
227 ms |
55688 KB |
Output is correct |
79 |
Correct |
242 ms |
55592 KB |
Output is correct |
80 |
Correct |
226 ms |
55760 KB |
Output is correct |
81 |
Correct |
440 ms |
54876 KB |
Output is correct |
82 |
Correct |
478 ms |
54760 KB |
Output is correct |
83 |
Correct |
463 ms |
54656 KB |
Output is correct |
84 |
Correct |
479 ms |
55180 KB |
Output is correct |
85 |
Correct |
497 ms |
54724 KB |
Output is correct |
86 |
Correct |
482 ms |
54816 KB |
Output is correct |
87 |
Correct |
464 ms |
54880 KB |
Output is correct |
88 |
Correct |
1074 ms |
50068 KB |
Output is correct |
89 |
Correct |
1012 ms |
49980 KB |
Output is correct |
90 |
Correct |
987 ms |
50068 KB |
Output is correct |
91 |
Correct |
1037 ms |
50068 KB |
Output is correct |
92 |
Correct |
1119 ms |
50072 KB |
Output is correct |
93 |
Correct |
1311 ms |
53740 KB |
Output is correct |
94 |
Execution timed out |
3061 ms |
52280 KB |
Time limit exceeded |
95 |
Halted |
0 ms |
0 KB |
- |