#pragma warning(disable:4996)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
vector<vector<ll>> circle;
vector<pair<ll, int>> sortRadius, sortX, sortY;
int skipX[300100], skipY[300100];
int xIdx[300100], yIdx[300100];
int ans[301000];
inline ll GetDist(ll x1, ll y1, ll x2, ll y2)
{
// 아 좌표값 마이너스도 들어오네
ll xx = max(x1, x2) - min(x1, x2);
ll yy = max(y1, y2) - min(y1, y2);
return (xx * xx) + (yy * yy);
}
bool comp(const pair<ll, int>& a, const pair<ll, int>& b)
{
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
bool compSort(const pair<ll, int>& a, const pair<ll, int>& b)
{
if (a.first == b.first)
return a.second < b.second;
return a.first > b.first;
}
int main()
{
ll x, y, r, r2;
int i;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%lld %lld %lld", &x, &y, &r);
//x = 1, y = 1, r = 3;
circle.push_back({ x,y,r });
sortRadius.push_back({ r,i });
sortX.push_back({ x,i });
sortY.push_back({ y,i });
skipX[i] = i + 1;
skipY[i] = i + 1;
}
sort(sortRadius.begin(), sortRadius.end(), compSort);
sort(sortX.begin(), sortX.end());
sort(sortY.begin(), sortY.end());
for (int i = 0; i < n; i++)
{
xIdx[sortX[i].second] = i;
yIdx[sortY[i].second] = i;
}
int cur, curcmp;
int xMin, xMax, yMin, yMax;
int next;
ll rr;
fill(ans, ans + n + 2, -1);
for (int curDelete = 0; curDelete < n; curDelete++)
{
cur = sortRadius[curDelete].second;
if (ans[cur] != -1)
continue;
x = circle[cur][0], y = circle[cur][1], r = circle[cur][2];
if (curDelete < n - 1)
r2 = r + sortRadius[curDelete + 1].first + 1;
else
r2 = r * 2 + 1;
// a이하를 찾아야하는데 lower bound는 a이상인걸 찾으니까.. 근데 그 이하인걸 찾아야하니 1빼줌
xMin = lower_bound(sortX.begin(), sortX.end(), pair<ll, int>(x - r2, -1), comp) - sortX.begin();
xMax = upper_bound(sortX.begin(), sortX.end(), pair<ll, int>(x + r2, 301000), comp) - sortX.begin();
yMin = lower_bound(sortY.begin(), sortY.end(), pair<ll, int>(y - r2, -1), comp) - sortY.begin();
yMax = upper_bound(sortY.begin(), sortY.end(), pair<ll, int>(y + r2, 301000), comp) - sortY.begin();
xMin--;
yMin--;
if (xMin < 0) xMin = 0;
if (yMin < 0) yMin = 0;
if (xMin >= sortX.size()) xMin = sortX.size() - 1;
if (yMin >= sortY.size()) yMin = sortY.size() - 1;
if (xMax >= sortX.size()) xMax = sortX.size() - 1;
if (yMax >= sortY.size()) yMax = sortY.size() - 1;
//xMin = 0, yMin = 0, xMax = n - 1, yMax = n - 1;
ans[cur] = cur;
if (xIdx[cur] - 1 >= 0)
{
skipX[xIdx[cur] - 1] = skipX[xIdx[cur]];
if (skipX[xIdx[cur] - 1] == 0) skipX[xIdx[cur] - 1] = n + 1;
}
if (yIdx[cur] - 1 >= 0)
{
skipY[yIdx[cur] - 1] = skipY[yIdx[cur]];
if (skipY[yIdx[cur] - 1] == 0) skipY[yIdx[cur] - 1] = n + 1;
}
//xIdx[cur]
if (xMax - xMin < yMax - yMin)
{
i = xMin;
while (i <= xMax)
{
curcmp = sortX[i].second;
next = skipX[i];
if (ans[curcmp] != -1)
{
i = next;
continue;
}
rr = r + circle[curcmp][2];
if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= rr * rr)
{
ans[curcmp] = cur;
//sortX.erase(sortX.begin() + i);
if (i - 1 >= 0)
skipX[i - 1] = skipX[i];
/*
if (yIdx[curcmp] - 1 >= 0)
{
skipY[yIdx[curcmp] - 1] = skipY[yIdx[curcmp]];
if (skipY[yIdx[curcmp] - 1] == 0) skipY[yIdx[curcmp] - 1] = n + 1;
}*/
}
i = next;
}
}
else
{
i = yMin;
while (i <= yMax)
{
curcmp = sortY[i].second;
next = skipY[i];
if (ans[curcmp] != -1)
{
i = next;
continue;
}
rr = r + circle[curcmp][2];
if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= rr * rr)
{
ans[curcmp] = cur;
//sortX.erase(sortX.begin() + i);
if (i - 1>= 0)
skipY[i - 1] = skipY[i];
/*
if (xIdx[curcmp] - 1 >= 0)
{
skipX[xIdx[curcmp] - 1] = skipX[xIdx[curcmp]];
if (skipX[yIdx[curcmp] - 1] == 0) skipX[xIdx[curcmp] - 1] = n + 1;
}*/
}
i = next;
}
/*
for (int i = yMax; i >= yMin; i--)
{
curcmp = sortY[i].second;
if (ans[curcmp]!= -1) continue;
rr = r + circle[curcmp][2];
if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= rr * rr)
{
ans[curcmp] = cur;
//sortY.erase(sortY.begin() + i);
}
}*/
}
}
for (int i = 0; i < n; i++)
printf("%d ", ans[i] + 1);
return 0;
}
Compilation message
circle_selection.cpp:1: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
1 | #pragma warning(disable:4996)
|
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:108:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | if (xMin >= sortX.size()) xMin = sortX.size() - 1;
| ~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:109:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | if (yMin >= sortY.size()) yMin = sortY.size() - 1;
| ~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:110:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | if (xMax >= sortX.size()) xMax = sortX.size() - 1;
| ~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:111:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | if (yMax >= sortY.size()) yMax = sortY.size() - 1;
| ~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%lld %lld %lld", &x, &y, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
5 ms |
1108 KB |
Output is correct |
20 |
Correct |
3 ms |
1108 KB |
Output is correct |
21 |
Correct |
4 ms |
1108 KB |
Output is correct |
22 |
Correct |
5 ms |
1108 KB |
Output is correct |
23 |
Correct |
5 ms |
1108 KB |
Output is correct |
24 |
Correct |
5 ms |
1108 KB |
Output is correct |
25 |
Correct |
5 ms |
1108 KB |
Output is correct |
26 |
Correct |
5 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
38732 KB |
Output is correct |
2 |
Correct |
215 ms |
38812 KB |
Output is correct |
3 |
Correct |
197 ms |
38524 KB |
Output is correct |
4 |
Correct |
220 ms |
38768 KB |
Output is correct |
5 |
Correct |
211 ms |
38584 KB |
Output is correct |
6 |
Correct |
299 ms |
38672 KB |
Output is correct |
7 |
Correct |
223 ms |
38640 KB |
Output is correct |
8 |
Correct |
226 ms |
38704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
195 ms |
13004 KB |
Output is correct |
3 |
Correct |
903 ms |
38688 KB |
Output is correct |
4 |
Correct |
879 ms |
38668 KB |
Output is correct |
5 |
Correct |
1176 ms |
37776 KB |
Output is correct |
6 |
Correct |
316 ms |
20212 KB |
Output is correct |
7 |
Correct |
111 ms |
10768 KB |
Output is correct |
8 |
Correct |
15 ms |
2440 KB |
Output is correct |
9 |
Correct |
928 ms |
38644 KB |
Output is correct |
10 |
Correct |
1671 ms |
38660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
570 ms |
38772 KB |
Output is correct |
2 |
Correct |
519 ms |
38600 KB |
Output is correct |
3 |
Correct |
848 ms |
38260 KB |
Output is correct |
4 |
Correct |
469 ms |
38644 KB |
Output is correct |
5 |
Correct |
489 ms |
38704 KB |
Output is correct |
6 |
Correct |
436 ms |
37980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
5 ms |
1108 KB |
Output is correct |
20 |
Correct |
3 ms |
1108 KB |
Output is correct |
21 |
Correct |
4 ms |
1108 KB |
Output is correct |
22 |
Correct |
5 ms |
1108 KB |
Output is correct |
23 |
Correct |
5 ms |
1108 KB |
Output is correct |
24 |
Correct |
5 ms |
1108 KB |
Output is correct |
25 |
Correct |
5 ms |
1108 KB |
Output is correct |
26 |
Correct |
5 ms |
1108 KB |
Output is correct |
27 |
Correct |
7 ms |
1672 KB |
Output is correct |
28 |
Correct |
7 ms |
1672 KB |
Output is correct |
29 |
Correct |
7 ms |
1744 KB |
Output is correct |
30 |
Correct |
11 ms |
1672 KB |
Output is correct |
31 |
Correct |
11 ms |
1720 KB |
Output is correct |
32 |
Correct |
11 ms |
1696 KB |
Output is correct |
33 |
Correct |
71 ms |
13016 KB |
Output is correct |
34 |
Correct |
71 ms |
12960 KB |
Output is correct |
35 |
Correct |
73 ms |
13020 KB |
Output is correct |
36 |
Correct |
166 ms |
15604 KB |
Output is correct |
37 |
Correct |
138 ms |
15672 KB |
Output is correct |
38 |
Correct |
148 ms |
15692 KB |
Output is correct |
39 |
Correct |
410 ms |
14076 KB |
Output is correct |
40 |
Correct |
409 ms |
14080 KB |
Output is correct |
41 |
Correct |
405 ms |
14072 KB |
Output is correct |
42 |
Correct |
199 ms |
14588 KB |
Output is correct |
43 |
Correct |
114 ms |
15676 KB |
Output is correct |
44 |
Correct |
124 ms |
15708 KB |
Output is correct |
45 |
Correct |
113 ms |
15592 KB |
Output is correct |
46 |
Correct |
113 ms |
15544 KB |
Output is correct |
47 |
Correct |
113 ms |
15644 KB |
Output is correct |
48 |
Correct |
118 ms |
15596 KB |
Output is correct |
49 |
Correct |
118 ms |
15548 KB |
Output is correct |
50 |
Correct |
116 ms |
15584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
5 ms |
1108 KB |
Output is correct |
20 |
Correct |
3 ms |
1108 KB |
Output is correct |
21 |
Correct |
4 ms |
1108 KB |
Output is correct |
22 |
Correct |
5 ms |
1108 KB |
Output is correct |
23 |
Correct |
5 ms |
1108 KB |
Output is correct |
24 |
Correct |
5 ms |
1108 KB |
Output is correct |
25 |
Correct |
5 ms |
1108 KB |
Output is correct |
26 |
Correct |
5 ms |
1108 KB |
Output is correct |
27 |
Correct |
194 ms |
38732 KB |
Output is correct |
28 |
Correct |
215 ms |
38812 KB |
Output is correct |
29 |
Correct |
197 ms |
38524 KB |
Output is correct |
30 |
Correct |
220 ms |
38768 KB |
Output is correct |
31 |
Correct |
211 ms |
38584 KB |
Output is correct |
32 |
Correct |
299 ms |
38672 KB |
Output is correct |
33 |
Correct |
223 ms |
38640 KB |
Output is correct |
34 |
Correct |
226 ms |
38704 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
195 ms |
13004 KB |
Output is correct |
37 |
Correct |
903 ms |
38688 KB |
Output is correct |
38 |
Correct |
879 ms |
38668 KB |
Output is correct |
39 |
Correct |
1176 ms |
37776 KB |
Output is correct |
40 |
Correct |
316 ms |
20212 KB |
Output is correct |
41 |
Correct |
111 ms |
10768 KB |
Output is correct |
42 |
Correct |
15 ms |
2440 KB |
Output is correct |
43 |
Correct |
928 ms |
38644 KB |
Output is correct |
44 |
Correct |
1671 ms |
38660 KB |
Output is correct |
45 |
Correct |
570 ms |
38772 KB |
Output is correct |
46 |
Correct |
519 ms |
38600 KB |
Output is correct |
47 |
Correct |
848 ms |
38260 KB |
Output is correct |
48 |
Correct |
469 ms |
38644 KB |
Output is correct |
49 |
Correct |
489 ms |
38704 KB |
Output is correct |
50 |
Correct |
436 ms |
37980 KB |
Output is correct |
51 |
Correct |
7 ms |
1672 KB |
Output is correct |
52 |
Correct |
7 ms |
1672 KB |
Output is correct |
53 |
Correct |
7 ms |
1744 KB |
Output is correct |
54 |
Correct |
11 ms |
1672 KB |
Output is correct |
55 |
Correct |
11 ms |
1720 KB |
Output is correct |
56 |
Correct |
11 ms |
1696 KB |
Output is correct |
57 |
Correct |
71 ms |
13016 KB |
Output is correct |
58 |
Correct |
71 ms |
12960 KB |
Output is correct |
59 |
Correct |
73 ms |
13020 KB |
Output is correct |
60 |
Correct |
166 ms |
15604 KB |
Output is correct |
61 |
Correct |
138 ms |
15672 KB |
Output is correct |
62 |
Correct |
148 ms |
15692 KB |
Output is correct |
63 |
Correct |
410 ms |
14076 KB |
Output is correct |
64 |
Correct |
409 ms |
14080 KB |
Output is correct |
65 |
Correct |
405 ms |
14072 KB |
Output is correct |
66 |
Correct |
199 ms |
14588 KB |
Output is correct |
67 |
Correct |
114 ms |
15676 KB |
Output is correct |
68 |
Correct |
124 ms |
15708 KB |
Output is correct |
69 |
Correct |
113 ms |
15592 KB |
Output is correct |
70 |
Correct |
113 ms |
15544 KB |
Output is correct |
71 |
Correct |
113 ms |
15644 KB |
Output is correct |
72 |
Correct |
118 ms |
15596 KB |
Output is correct |
73 |
Correct |
118 ms |
15548 KB |
Output is correct |
74 |
Correct |
116 ms |
15584 KB |
Output is correct |
75 |
Correct |
235 ms |
47768 KB |
Output is correct |
76 |
Correct |
236 ms |
47572 KB |
Output is correct |
77 |
Correct |
231 ms |
47704 KB |
Output is correct |
78 |
Correct |
237 ms |
47456 KB |
Output is correct |
79 |
Correct |
283 ms |
47396 KB |
Output is correct |
80 |
Correct |
230 ms |
47472 KB |
Output is correct |
81 |
Correct |
808 ms |
46680 KB |
Output is correct |
82 |
Correct |
730 ms |
46580 KB |
Output is correct |
83 |
Correct |
701 ms |
46460 KB |
Output is correct |
84 |
Correct |
1190 ms |
47016 KB |
Output is correct |
85 |
Correct |
759 ms |
46584 KB |
Output is correct |
86 |
Correct |
726 ms |
46636 KB |
Output is correct |
87 |
Correct |
853 ms |
46676 KB |
Output is correct |
88 |
Execution timed out |
3074 ms |
40024 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |