#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 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;
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 });
}
sort(sortRadius.begin(), sortRadius.end(), compSort);
sort(sortX.begin(), sortX.end());
sort(sortY.begin(), sortY.end());
int cur, curcmp;
int xMin, xMax, yMin, yMax;
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];
r2 = r * 3 + 2;
// 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 (xMax - xMin < yMax - yMin)
{
curcmp = sortX[max(0, xMin - 1)].second;
int beforeX = circle[curcmp][0];
/*
for (int i = xMin; i >= 0; i--)
{
curcmp = sortX[i].second;
if (beforeX > circle[curcmp][0])
break;
if (ans[curcmp] != -1) continue;
if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= (ll)(((r + circle[curcmp][2]) * (r + circle[curcmp][2]))))
ans[curcmp] = cur;
}*/
for (int i = xMax; i >= xMin; i--)
{
curcmp = sortX[i].second;
if (ans[curcmp] != -1) continue;
if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= (ll)(((r + circle[curcmp][2]) * (r + circle[curcmp][2]))))
{
ans[curcmp] = cur;
sortX.erase(sortX.begin() + i);
}
}
}
else
{
curcmp = sortY[max(0, yMin - 1)].second;
int beforeY = circle[curcmp][1];
//for (int i = yMin; i >= 0; i--)
//{
// curcmp = sortY[i].second;
// if (beforeY > circle[curcmp][1])
// break;
// if (ans[curcmp] != -1) continue;
// if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= (ll)(((r + circle[curcmp][2]) * (r + circle[curcmp][2]))))
// ans[curcmp] = cur;
//}
for (int i = yMax; i >= yMin; i--)
{
curcmp = sortY[i].second;
if (ans[curcmp]!= -1) continue;
if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= (ll)(((r + circle[curcmp][2]) * (r + circle[curcmp][2]))))
{
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:91:12: 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]
91 | if (xMin >= sortX.size()) xMin = sortX.size() - 1;
| ~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:92:12: 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]
92 | if (yMin >= sortY.size()) yMin = sortY.size() - 1;
| ~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:93:12: 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]
93 | if (xMax >= sortX.size()) xMax = sortX.size() - 1;
| ~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:94:12: 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]
94 | if (yMax >= sortY.size()) yMax = sortY.size() - 1;
| ~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:104:8: warning: unused variable 'beforeX' [-Wunused-variable]
104 | int beforeX = circle[curcmp][0];
| ^~~~~~~
circle_selection.cpp:131:8: warning: unused variable 'beforeY' [-Wunused-variable]
131 | int beforeY = circle[curcmp][1];
| ^~~~~~~
circle_selection.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%lld %lld %lld", &x, &y, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
992 KB |
Output is correct |
20 |
Correct |
5 ms |
980 KB |
Output is correct |
21 |
Correct |
7 ms |
1080 KB |
Output is correct |
22 |
Correct |
6 ms |
980 KB |
Output is correct |
23 |
Correct |
5 ms |
980 KB |
Output is correct |
24 |
Correct |
5 ms |
980 KB |
Output is correct |
25 |
Correct |
5 ms |
1072 KB |
Output is correct |
26 |
Correct |
6 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
621 ms |
34080 KB |
Output is correct |
2 |
Execution timed out |
3073 ms |
33136 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
234 ms |
11400 KB |
Output is correct |
3 |
Correct |
1263 ms |
33956 KB |
Output is correct |
4 |
Correct |
1260 ms |
33956 KB |
Output is correct |
5 |
Execution timed out |
3079 ms |
33060 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
662 ms |
33940 KB |
Output is correct |
2 |
Correct |
456 ms |
33952 KB |
Output is correct |
3 |
Execution timed out |
3088 ms |
33140 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
992 KB |
Output is correct |
20 |
Correct |
5 ms |
980 KB |
Output is correct |
21 |
Correct |
7 ms |
1080 KB |
Output is correct |
22 |
Correct |
6 ms |
980 KB |
Output is correct |
23 |
Correct |
5 ms |
980 KB |
Output is correct |
24 |
Correct |
5 ms |
980 KB |
Output is correct |
25 |
Correct |
5 ms |
1072 KB |
Output is correct |
26 |
Correct |
6 ms |
1152 KB |
Output is correct |
27 |
Correct |
7 ms |
1544 KB |
Output is correct |
28 |
Correct |
7 ms |
1492 KB |
Output is correct |
29 |
Correct |
7 ms |
1544 KB |
Output is correct |
30 |
Correct |
11 ms |
1532 KB |
Output is correct |
31 |
Correct |
13 ms |
1544 KB |
Output is correct |
32 |
Correct |
11 ms |
1544 KB |
Output is correct |
33 |
Correct |
69 ms |
11392 KB |
Output is correct |
34 |
Correct |
69 ms |
11408 KB |
Output is correct |
35 |
Correct |
306 ms |
11484 KB |
Output is correct |
36 |
Correct |
146 ms |
11424 KB |
Output is correct |
37 |
Correct |
144 ms |
11404 KB |
Output is correct |
38 |
Correct |
165 ms |
11388 KB |
Output is correct |
39 |
Correct |
2505 ms |
11396 KB |
Output is correct |
40 |
Correct |
2415 ms |
11388 KB |
Output is correct |
41 |
Correct |
2513 ms |
11396 KB |
Output is correct |
42 |
Correct |
1900 ms |
11456 KB |
Output is correct |
43 |
Correct |
415 ms |
11400 KB |
Output is correct |
44 |
Correct |
409 ms |
11388 KB |
Output is correct |
45 |
Correct |
413 ms |
11392 KB |
Output is correct |
46 |
Correct |
421 ms |
11512 KB |
Output is correct |
47 |
Correct |
404 ms |
11460 KB |
Output is correct |
48 |
Correct |
415 ms |
11444 KB |
Output is correct |
49 |
Correct |
400 ms |
11392 KB |
Output is correct |
50 |
Correct |
416 ms |
11420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
992 KB |
Output is correct |
20 |
Correct |
5 ms |
980 KB |
Output is correct |
21 |
Correct |
7 ms |
1080 KB |
Output is correct |
22 |
Correct |
6 ms |
980 KB |
Output is correct |
23 |
Correct |
5 ms |
980 KB |
Output is correct |
24 |
Correct |
5 ms |
980 KB |
Output is correct |
25 |
Correct |
5 ms |
1072 KB |
Output is correct |
26 |
Correct |
6 ms |
1152 KB |
Output is correct |
27 |
Correct |
621 ms |
34080 KB |
Output is correct |
28 |
Execution timed out |
3073 ms |
33136 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |