#include <stdio.h>
#include <algorithm>
#include <list>
#include <map>
#include <unordered_map>
#define getchar getchar_unlocked
#define putchar putchar_unlocked
using namespace std;
typedef long long i64;
int rd()
{
int k = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
{
k = (k << 1) + (k << 3) + (c ^ 48);
c = getchar();
}
return f == 1 ? k : -k;
}
void wr(int x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
wr(x / 10);
putchar((x % 10) ^ '0');
}
const int maxn = 300010;
struct point
{
int x, y;
point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
bool operator< (const point& o) const { return (x ^ o.x) ? x < o.x : y < o.y; }
bool operator==(const point& o) const { return (x == o.x) && (y == o.y); }
};
struct point_hash
{
size_t operator()(const point &a) const { return hash<int>()(a.x) ^ hash<int>()(a.y); }
};
struct circle
{
point c;
int r;
} c[maxn];
int n, idx[maxn], ans[maxn];
bool cmp(int a, int b)
{
if (c[a].r ^ c[b].r)
return c[a].r > c[b].r;
else
return a < b;
}
map<point, list<int>> mp;
// unordered_map<point, list<int>, point_hash> mp;
int grid_r;
void build(int r)
{
grid_r = r;
mp.clear();
for (int i = 1; i <= n; ++i)
if (!ans[i])
mp[point(c[i].c.x / grid_r, c[i].c.y / grid_r)].push_back(i);
}
bool check(int i, int j)
{
i64 dis = 1ll * (c[i].c.x - c[j].c.x) * (c[i].c.x - c[j].c.x) + 1ll * (c[i].c.y - c[j].c.y) * (c[i].c.y - c[j].c.y);
return dis <= 1ll * (c[i].r + c[j].r) * (c[i].r + c[j].r);
}
int main()
{
n = rd();
for (int i = 1; i <= n; ++i)
c[i].c.x = rd(), c[i].c.y = rd(), c[i].r = rd();
for (int i = 1; i <= n; ++i)
idx[i] = i;
sort(idx + 1, idx + n + 1, cmp);
build(c[idx[1]].r << 1);
for (int i = 1; i <= n; ++i)
{
if (ans[idx[i]])
continue;
if ((i64)grid_r > ((i64)(c[idx[i]].r) << 2))
build(c[idx[i]].r << 1);
int x = c[idx[i]].c.x / grid_r, y = c[idx[i]].c.y / grid_r;
for (int dx = -1; dx <= 1; ++dx)
for (int dy = -1; dy <= 1; ++dy)
{
point pt = point(x + dx, y + dy);
if (!mp.count(pt))
continue;
list<int>& it = mp[pt];
for (list<int>::iterator itt = it.begin(); itt != it.end(); )
{
if (check(idx[i], *itt))
ans[*itt] = idx[i], it.erase(itt++);
else
++itt;
}
}
}
for (int i = 1; i <= n; ++i)
wr(ans[i]), putchar(' ');
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3820 KB |
Output is correct |
2 |
Correct |
2 ms |
3796 KB |
Output is correct |
3 |
Correct |
2 ms |
3796 KB |
Output is correct |
4 |
Correct |
2 ms |
3820 KB |
Output is correct |
5 |
Correct |
2 ms |
3796 KB |
Output is correct |
6 |
Correct |
2 ms |
3796 KB |
Output is correct |
7 |
Correct |
2 ms |
3796 KB |
Output is correct |
8 |
Correct |
2 ms |
3796 KB |
Output is correct |
9 |
Correct |
2 ms |
3796 KB |
Output is correct |
10 |
Correct |
2 ms |
3796 KB |
Output is correct |
11 |
Correct |
2 ms |
3796 KB |
Output is correct |
12 |
Correct |
2 ms |
3796 KB |
Output is correct |
13 |
Correct |
1 ms |
3796 KB |
Output is correct |
14 |
Correct |
2 ms |
3784 KB |
Output is correct |
15 |
Correct |
2 ms |
3796 KB |
Output is correct |
16 |
Correct |
2 ms |
3796 KB |
Output is correct |
17 |
Correct |
2 ms |
3828 KB |
Output is correct |
18 |
Correct |
2 ms |
3880 KB |
Output is correct |
19 |
Correct |
3 ms |
4084 KB |
Output is correct |
20 |
Correct |
4 ms |
4180 KB |
Output is correct |
21 |
Correct |
3 ms |
4184 KB |
Output is correct |
22 |
Correct |
7 ms |
4564 KB |
Output is correct |
23 |
Correct |
7 ms |
4564 KB |
Output is correct |
24 |
Correct |
7 ms |
4564 KB |
Output is correct |
25 |
Correct |
6 ms |
4472 KB |
Output is correct |
26 |
Correct |
6 ms |
4536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
24304 KB |
Output is correct |
2 |
Correct |
88 ms |
24256 KB |
Output is correct |
3 |
Correct |
93 ms |
24036 KB |
Output is correct |
4 |
Correct |
83 ms |
24244 KB |
Output is correct |
5 |
Correct |
127 ms |
22216 KB |
Output is correct |
6 |
Correct |
322 ms |
28960 KB |
Output is correct |
7 |
Correct |
153 ms |
22896 KB |
Output is correct |
8 |
Correct |
177 ms |
23740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3732 KB |
Output is correct |
2 |
Correct |
194 ms |
18784 KB |
Output is correct |
3 |
Correct |
1205 ms |
48588 KB |
Output is correct |
4 |
Correct |
1082 ms |
49008 KB |
Output is correct |
5 |
Correct |
945 ms |
41288 KB |
Output is correct |
6 |
Correct |
370 ms |
22716 KB |
Output is correct |
7 |
Correct |
100 ms |
13836 KB |
Output is correct |
8 |
Correct |
15 ms |
5848 KB |
Output is correct |
9 |
Correct |
1389 ms |
47556 KB |
Output is correct |
10 |
Correct |
902 ms |
40336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
809 ms |
48856 KB |
Output is correct |
2 |
Correct |
530 ms |
48068 KB |
Output is correct |
3 |
Correct |
188 ms |
27240 KB |
Output is correct |
4 |
Correct |
580 ms |
48356 KB |
Output is correct |
5 |
Correct |
585 ms |
48592 KB |
Output is correct |
6 |
Correct |
125 ms |
25584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3820 KB |
Output is correct |
2 |
Correct |
2 ms |
3796 KB |
Output is correct |
3 |
Correct |
2 ms |
3796 KB |
Output is correct |
4 |
Correct |
2 ms |
3820 KB |
Output is correct |
5 |
Correct |
2 ms |
3796 KB |
Output is correct |
6 |
Correct |
2 ms |
3796 KB |
Output is correct |
7 |
Correct |
2 ms |
3796 KB |
Output is correct |
8 |
Correct |
2 ms |
3796 KB |
Output is correct |
9 |
Correct |
2 ms |
3796 KB |
Output is correct |
10 |
Correct |
2 ms |
3796 KB |
Output is correct |
11 |
Correct |
2 ms |
3796 KB |
Output is correct |
12 |
Correct |
2 ms |
3796 KB |
Output is correct |
13 |
Correct |
1 ms |
3796 KB |
Output is correct |
14 |
Correct |
2 ms |
3784 KB |
Output is correct |
15 |
Correct |
2 ms |
3796 KB |
Output is correct |
16 |
Correct |
2 ms |
3796 KB |
Output is correct |
17 |
Correct |
2 ms |
3828 KB |
Output is correct |
18 |
Correct |
2 ms |
3880 KB |
Output is correct |
19 |
Correct |
3 ms |
4084 KB |
Output is correct |
20 |
Correct |
4 ms |
4180 KB |
Output is correct |
21 |
Correct |
3 ms |
4184 KB |
Output is correct |
22 |
Correct |
7 ms |
4564 KB |
Output is correct |
23 |
Correct |
7 ms |
4564 KB |
Output is correct |
24 |
Correct |
7 ms |
4564 KB |
Output is correct |
25 |
Correct |
6 ms |
4472 KB |
Output is correct |
26 |
Correct |
6 ms |
4536 KB |
Output is correct |
27 |
Correct |
5 ms |
4480 KB |
Output is correct |
28 |
Correct |
4 ms |
4564 KB |
Output is correct |
29 |
Correct |
4 ms |
4476 KB |
Output is correct |
30 |
Correct |
15 ms |
5248 KB |
Output is correct |
31 |
Correct |
16 ms |
5244 KB |
Output is correct |
32 |
Correct |
16 ms |
5264 KB |
Output is correct |
33 |
Correct |
29 ms |
11332 KB |
Output is correct |
34 |
Correct |
31 ms |
11364 KB |
Output is correct |
35 |
Correct |
33 ms |
11228 KB |
Output is correct |
36 |
Correct |
196 ms |
18636 KB |
Output is correct |
37 |
Correct |
183 ms |
18684 KB |
Output is correct |
38 |
Correct |
211 ms |
18716 KB |
Output is correct |
39 |
Correct |
172 ms |
13724 KB |
Output is correct |
40 |
Correct |
170 ms |
13772 KB |
Output is correct |
41 |
Correct |
158 ms |
13772 KB |
Output is correct |
42 |
Correct |
78 ms |
11844 KB |
Output is correct |
43 |
Correct |
161 ms |
18380 KB |
Output is correct |
44 |
Correct |
116 ms |
18256 KB |
Output is correct |
45 |
Correct |
149 ms |
18248 KB |
Output is correct |
46 |
Correct |
159 ms |
18296 KB |
Output is correct |
47 |
Correct |
129 ms |
18296 KB |
Output is correct |
48 |
Correct |
138 ms |
18384 KB |
Output is correct |
49 |
Correct |
126 ms |
18264 KB |
Output is correct |
50 |
Correct |
151 ms |
18320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3820 KB |
Output is correct |
2 |
Correct |
2 ms |
3796 KB |
Output is correct |
3 |
Correct |
2 ms |
3796 KB |
Output is correct |
4 |
Correct |
2 ms |
3820 KB |
Output is correct |
5 |
Correct |
2 ms |
3796 KB |
Output is correct |
6 |
Correct |
2 ms |
3796 KB |
Output is correct |
7 |
Correct |
2 ms |
3796 KB |
Output is correct |
8 |
Correct |
2 ms |
3796 KB |
Output is correct |
9 |
Correct |
2 ms |
3796 KB |
Output is correct |
10 |
Correct |
2 ms |
3796 KB |
Output is correct |
11 |
Correct |
2 ms |
3796 KB |
Output is correct |
12 |
Correct |
2 ms |
3796 KB |
Output is correct |
13 |
Correct |
1 ms |
3796 KB |
Output is correct |
14 |
Correct |
2 ms |
3784 KB |
Output is correct |
15 |
Correct |
2 ms |
3796 KB |
Output is correct |
16 |
Correct |
2 ms |
3796 KB |
Output is correct |
17 |
Correct |
2 ms |
3828 KB |
Output is correct |
18 |
Correct |
2 ms |
3880 KB |
Output is correct |
19 |
Correct |
3 ms |
4084 KB |
Output is correct |
20 |
Correct |
4 ms |
4180 KB |
Output is correct |
21 |
Correct |
3 ms |
4184 KB |
Output is correct |
22 |
Correct |
7 ms |
4564 KB |
Output is correct |
23 |
Correct |
7 ms |
4564 KB |
Output is correct |
24 |
Correct |
7 ms |
4564 KB |
Output is correct |
25 |
Correct |
6 ms |
4472 KB |
Output is correct |
26 |
Correct |
6 ms |
4536 KB |
Output is correct |
27 |
Correct |
87 ms |
24304 KB |
Output is correct |
28 |
Correct |
88 ms |
24256 KB |
Output is correct |
29 |
Correct |
93 ms |
24036 KB |
Output is correct |
30 |
Correct |
83 ms |
24244 KB |
Output is correct |
31 |
Correct |
127 ms |
22216 KB |
Output is correct |
32 |
Correct |
322 ms |
28960 KB |
Output is correct |
33 |
Correct |
153 ms |
22896 KB |
Output is correct |
34 |
Correct |
177 ms |
23740 KB |
Output is correct |
35 |
Correct |
2 ms |
3732 KB |
Output is correct |
36 |
Correct |
194 ms |
18784 KB |
Output is correct |
37 |
Correct |
1205 ms |
48588 KB |
Output is correct |
38 |
Correct |
1082 ms |
49008 KB |
Output is correct |
39 |
Correct |
945 ms |
41288 KB |
Output is correct |
40 |
Correct |
370 ms |
22716 KB |
Output is correct |
41 |
Correct |
100 ms |
13836 KB |
Output is correct |
42 |
Correct |
15 ms |
5848 KB |
Output is correct |
43 |
Correct |
1389 ms |
47556 KB |
Output is correct |
44 |
Correct |
902 ms |
40336 KB |
Output is correct |
45 |
Correct |
809 ms |
48856 KB |
Output is correct |
46 |
Correct |
530 ms |
48068 KB |
Output is correct |
47 |
Correct |
188 ms |
27240 KB |
Output is correct |
48 |
Correct |
580 ms |
48356 KB |
Output is correct |
49 |
Correct |
585 ms |
48592 KB |
Output is correct |
50 |
Correct |
125 ms |
25584 KB |
Output is correct |
51 |
Correct |
5 ms |
4480 KB |
Output is correct |
52 |
Correct |
4 ms |
4564 KB |
Output is correct |
53 |
Correct |
4 ms |
4476 KB |
Output is correct |
54 |
Correct |
15 ms |
5248 KB |
Output is correct |
55 |
Correct |
16 ms |
5244 KB |
Output is correct |
56 |
Correct |
16 ms |
5264 KB |
Output is correct |
57 |
Correct |
29 ms |
11332 KB |
Output is correct |
58 |
Correct |
31 ms |
11364 KB |
Output is correct |
59 |
Correct |
33 ms |
11228 KB |
Output is correct |
60 |
Correct |
196 ms |
18636 KB |
Output is correct |
61 |
Correct |
183 ms |
18684 KB |
Output is correct |
62 |
Correct |
211 ms |
18716 KB |
Output is correct |
63 |
Correct |
172 ms |
13724 KB |
Output is correct |
64 |
Correct |
170 ms |
13772 KB |
Output is correct |
65 |
Correct |
158 ms |
13772 KB |
Output is correct |
66 |
Correct |
78 ms |
11844 KB |
Output is correct |
67 |
Correct |
161 ms |
18380 KB |
Output is correct |
68 |
Correct |
116 ms |
18256 KB |
Output is correct |
69 |
Correct |
149 ms |
18248 KB |
Output is correct |
70 |
Correct |
159 ms |
18296 KB |
Output is correct |
71 |
Correct |
129 ms |
18296 KB |
Output is correct |
72 |
Correct |
138 ms |
18384 KB |
Output is correct |
73 |
Correct |
126 ms |
18264 KB |
Output is correct |
74 |
Correct |
151 ms |
18320 KB |
Output is correct |
75 |
Correct |
107 ms |
26544 KB |
Output is correct |
76 |
Correct |
109 ms |
26384 KB |
Output is correct |
77 |
Correct |
100 ms |
26544 KB |
Output is correct |
78 |
Correct |
110 ms |
26268 KB |
Output is correct |
79 |
Correct |
171 ms |
26160 KB |
Output is correct |
80 |
Correct |
92 ms |
26304 KB |
Output is correct |
81 |
Correct |
1268 ms |
48964 KB |
Output is correct |
82 |
Correct |
1292 ms |
48788 KB |
Output is correct |
83 |
Correct |
1181 ms |
48740 KB |
Output is correct |
84 |
Correct |
1187 ms |
49164 KB |
Output is correct |
85 |
Correct |
1150 ms |
48832 KB |
Output is correct |
86 |
Correct |
1092 ms |
48912 KB |
Output is correct |
87 |
Correct |
1231 ms |
48384 KB |
Output is correct |
88 |
Correct |
757 ms |
33928 KB |
Output is correct |
89 |
Correct |
763 ms |
33932 KB |
Output is correct |
90 |
Correct |
659 ms |
33956 KB |
Output is correct |
91 |
Correct |
632 ms |
33876 KB |
Output is correct |
92 |
Correct |
672 ms |
33876 KB |
Output is correct |
93 |
Correct |
879 ms |
47824 KB |
Output is correct |
94 |
Correct |
922 ms |
47932 KB |
Output is correct |
95 |
Correct |
825 ms |
47792 KB |
Output is correct |
96 |
Correct |
784 ms |
47840 KB |
Output is correct |
97 |
Correct |
1033 ms |
47872 KB |
Output is correct |
98 |
Correct |
356 ms |
30724 KB |
Output is correct |
99 |
Correct |
967 ms |
47932 KB |
Output is correct |
100 |
Correct |
735 ms |
47644 KB |
Output is correct |
101 |
Correct |
801 ms |
35712 KB |
Output is correct |
102 |
Correct |
862 ms |
46636 KB |
Output is correct |
103 |
Correct |
1224 ms |
46896 KB |
Output is correct |
104 |
Correct |
1037 ms |
47692 KB |
Output is correct |
105 |
Correct |
434 ms |
28180 KB |
Output is correct |
106 |
Correct |
602 ms |
45636 KB |
Output is correct |
107 |
Correct |
598 ms |
45760 KB |
Output is correct |
108 |
Correct |
645 ms |
45720 KB |
Output is correct |
109 |
Correct |
610 ms |
45732 KB |
Output is correct |
110 |
Correct |
573 ms |
45712 KB |
Output is correct |
111 |
Correct |
523 ms |
45720 KB |
Output is correct |
112 |
Correct |
626 ms |
45744 KB |
Output is correct |
113 |
Correct |
560 ms |
45724 KB |
Output is correct |
114 |
Correct |
592 ms |
45736 KB |
Output is correct |
115 |
Correct |
564 ms |
45716 KB |
Output is correct |
116 |
Correct |
512 ms |
45724 KB |
Output is correct |