#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
vector<vector<ll>> circle;
vector<pair<ll, int>> sortRadius;
//set<pair<ll,int>> sortX, sortY;
//int skipX[300100], skipY[300100];
//int xIdx[300100], yIdx[300100];
set<vector<ll>> circleSet;
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;
}
map<pair<ll, ll>, multiset<vector<ll>>> SetGrid(ll gridSize)
{
map<pair<ll, ll>, multiset<vector<ll>>> myGrid;
ll x, y, r, i;
for (auto c = circleSet.begin(); c != circleSet.end(); c++)
{
x = (*c)[0], y = (*c)[1], r = (*c)[2], i = (*c)[3];
if (myGrid.insert({ {x / gridSize, y / gridSize},{{x,y,r,i}} }).second == false)
{
auto iter = myGrid.find({ x / gridSize, y / gridSize });
(*iter).second.insert({ x,y,r,i });
}
}
return myGrid;
}
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;
//좌표는 양수로만 그래야 그리드계산 편함
x += 1000000000L;
y += 1000000000L;
//1000000000
circle.push_back({ x,y,r });
circleSet.insert({ x,y,r,i });
sortRadius.push_back({ r,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;
ll rr;
fill(ans, ans + n + 2, -1);
ll gridSize = sortRadius[0].first * 2LL;
map<pair<ll, ll>, multiset<vector<ll>>> gridAll = SetGrid(gridSize);
ll gridX, gridY;
ll nx, ny, nr;
int ni;
multiset<vector<ll>> curGrids;
for (int curDelete = 0; curDelete < n; curDelete++)
{
cur = sortRadius[curDelete].second;
if (ans[cur] != -1)
continue;
if (gridSize / 3 >= sortRadius[curDelete].first*2LL && gridSize>3)
{
gridSize /= 3;
gridAll = SetGrid(gridSize);
}
ans[cur] = cur;
x = circle[cur][0], y = circle[cur][1], r = circle[cur][2];
gridX = x / gridSize, gridY = y / gridSize;
circleSet.erase({ x,y,r,cur });
(*gridAll.find({ gridX,gridY })).second.erase({ x,y,r,cur });
for (int curGridX = gridX - 1; curGridX <= gridX + 1; curGridX++)
{
for (int curGridY = gridY - 1; curGridY <= gridY + 1; curGridY++)
{
auto ggg = gridAll.find({ curGridX, curGridY });
if (ggg == gridAll.end())
continue;
curGrids = (*ggg).second;
vector<multiset<vector<ll>>::iterator> eraseItems;
for (auto curCircle = curGrids.begin(); curCircle != curGrids.end(); curCircle++)
{
nx = (*curCircle)[0], ny = (*curCircle)[1], nr = (*curCircle)[2], ni = (*curCircle)[3];
if (ans[ni] != -1)
continue;
if (GetDist(x, y, nx, ny) <= (r + nr) * (r + nr))
{
ans[ni] = cur ;
eraseItems.push_back(curCircle);
circleSet.erase({ nx,ny,nr,ni });//log n 최대 n번
}
}
for (auto eraseIt : eraseItems)
curGrids.erase(eraseIt);//log n 최대 n*32 번
}
}
}
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:74:17: warning: unused variable 'r2' [-Wunused-variable]
74 | ll x, y, r, r2;
| ^~
circle_selection.cpp:75:9: warning: unused variable 'i' [-Wunused-variable]
75 | int i;
| ^
circle_selection.cpp:96:14: warning: unused variable 'curcmp' [-Wunused-variable]
96 | int cur, curcmp;
| ^~~~~~
circle_selection.cpp:98:8: warning: unused variable 'rr' [-Wunused-variable]
98 | ll rr;
| ^~
circle_selection.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | scanf("%lld %lld %lld", &x, &y, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
236 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
7 ms |
2516 KB |
Output is correct |
20 |
Correct |
7 ms |
2260 KB |
Output is correct |
21 |
Correct |
12 ms |
2416 KB |
Output is correct |
22 |
Correct |
12 ms |
2516 KB |
Output is correct |
23 |
Correct |
13 ms |
2520 KB |
Output is correct |
24 |
Correct |
12 ms |
2516 KB |
Output is correct |
25 |
Correct |
14 ms |
2428 KB |
Output is correct |
26 |
Correct |
12 ms |
2516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
896 ms |
116100 KB |
Output is correct |
2 |
Correct |
988 ms |
116884 KB |
Output is correct |
3 |
Correct |
930 ms |
120896 KB |
Output is correct |
4 |
Correct |
774 ms |
130028 KB |
Output is correct |
5 |
Correct |
827 ms |
95324 KB |
Output is correct |
6 |
Correct |
1105 ms |
104584 KB |
Output is correct |
7 |
Correct |
888 ms |
96068 KB |
Output is correct |
8 |
Correct |
912 ms |
97292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
534 ms |
43904 KB |
Output is correct |
3 |
Correct |
2092 ms |
130052 KB |
Output is correct |
4 |
Correct |
2151 ms |
130116 KB |
Output is correct |
5 |
Correct |
1870 ms |
123312 KB |
Output is correct |
6 |
Correct |
729 ms |
62112 KB |
Output is correct |
7 |
Correct |
291 ms |
33068 KB |
Output is correct |
8 |
Correct |
34 ms |
7020 KB |
Output is correct |
9 |
Correct |
2109 ms |
144604 KB |
Output is correct |
10 |
Correct |
1716 ms |
136096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1563 ms |
130008 KB |
Output is correct |
2 |
Correct |
1496 ms |
130028 KB |
Output is correct |
3 |
Correct |
1153 ms |
99140 KB |
Output is correct |
4 |
Correct |
1406 ms |
130168 KB |
Output is correct |
5 |
Correct |
1406 ms |
130032 KB |
Output is correct |
6 |
Correct |
1113 ms |
96904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
236 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
7 ms |
2516 KB |
Output is correct |
20 |
Correct |
7 ms |
2260 KB |
Output is correct |
21 |
Correct |
12 ms |
2416 KB |
Output is correct |
22 |
Correct |
12 ms |
2516 KB |
Output is correct |
23 |
Correct |
13 ms |
2520 KB |
Output is correct |
24 |
Correct |
12 ms |
2516 KB |
Output is correct |
25 |
Correct |
14 ms |
2428 KB |
Output is correct |
26 |
Correct |
12 ms |
2516 KB |
Output is correct |
27 |
Correct |
14 ms |
4008 KB |
Output is correct |
28 |
Correct |
14 ms |
4348 KB |
Output is correct |
29 |
Correct |
14 ms |
4236 KB |
Output is correct |
30 |
Correct |
26 ms |
4704 KB |
Output is correct |
31 |
Correct |
25 ms |
4736 KB |
Output is correct |
32 |
Correct |
24 ms |
4744 KB |
Output is correct |
33 |
Correct |
189 ms |
46028 KB |
Output is correct |
34 |
Correct |
187 ms |
39324 KB |
Output is correct |
35 |
Correct |
246 ms |
37224 KB |
Output is correct |
36 |
Correct |
472 ms |
43860 KB |
Output is correct |
37 |
Correct |
477 ms |
43892 KB |
Output is correct |
38 |
Correct |
503 ms |
43884 KB |
Output is correct |
39 |
Correct |
2239 ms |
53180 KB |
Output is correct |
40 |
Correct |
2140 ms |
53228 KB |
Output is correct |
41 |
Correct |
2148 ms |
53308 KB |
Output is correct |
42 |
Correct |
292 ms |
34556 KB |
Output is correct |
43 |
Correct |
333 ms |
43244 KB |
Output is correct |
44 |
Correct |
346 ms |
43232 KB |
Output is correct |
45 |
Correct |
353 ms |
43228 KB |
Output is correct |
46 |
Correct |
362 ms |
43252 KB |
Output is correct |
47 |
Correct |
343 ms |
43244 KB |
Output is correct |
48 |
Correct |
336 ms |
43248 KB |
Output is correct |
49 |
Correct |
348 ms |
43332 KB |
Output is correct |
50 |
Correct |
347 ms |
43232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
236 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
7 ms |
2516 KB |
Output is correct |
20 |
Correct |
7 ms |
2260 KB |
Output is correct |
21 |
Correct |
12 ms |
2416 KB |
Output is correct |
22 |
Correct |
12 ms |
2516 KB |
Output is correct |
23 |
Correct |
13 ms |
2520 KB |
Output is correct |
24 |
Correct |
12 ms |
2516 KB |
Output is correct |
25 |
Correct |
14 ms |
2428 KB |
Output is correct |
26 |
Correct |
12 ms |
2516 KB |
Output is correct |
27 |
Correct |
896 ms |
116100 KB |
Output is correct |
28 |
Correct |
988 ms |
116884 KB |
Output is correct |
29 |
Correct |
930 ms |
120896 KB |
Output is correct |
30 |
Correct |
774 ms |
130028 KB |
Output is correct |
31 |
Correct |
827 ms |
95324 KB |
Output is correct |
32 |
Correct |
1105 ms |
104584 KB |
Output is correct |
33 |
Correct |
888 ms |
96068 KB |
Output is correct |
34 |
Correct |
912 ms |
97292 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
534 ms |
43904 KB |
Output is correct |
37 |
Correct |
2092 ms |
130052 KB |
Output is correct |
38 |
Correct |
2151 ms |
130116 KB |
Output is correct |
39 |
Correct |
1870 ms |
123312 KB |
Output is correct |
40 |
Correct |
729 ms |
62112 KB |
Output is correct |
41 |
Correct |
291 ms |
33068 KB |
Output is correct |
42 |
Correct |
34 ms |
7020 KB |
Output is correct |
43 |
Correct |
2109 ms |
144604 KB |
Output is correct |
44 |
Correct |
1716 ms |
136096 KB |
Output is correct |
45 |
Correct |
1563 ms |
130008 KB |
Output is correct |
46 |
Correct |
1496 ms |
130028 KB |
Output is correct |
47 |
Correct |
1153 ms |
99140 KB |
Output is correct |
48 |
Correct |
1406 ms |
130168 KB |
Output is correct |
49 |
Correct |
1406 ms |
130032 KB |
Output is correct |
50 |
Correct |
1113 ms |
96904 KB |
Output is correct |
51 |
Correct |
14 ms |
4008 KB |
Output is correct |
52 |
Correct |
14 ms |
4348 KB |
Output is correct |
53 |
Correct |
14 ms |
4236 KB |
Output is correct |
54 |
Correct |
26 ms |
4704 KB |
Output is correct |
55 |
Correct |
25 ms |
4736 KB |
Output is correct |
56 |
Correct |
24 ms |
4744 KB |
Output is correct |
57 |
Correct |
189 ms |
46028 KB |
Output is correct |
58 |
Correct |
187 ms |
39324 KB |
Output is correct |
59 |
Correct |
246 ms |
37224 KB |
Output is correct |
60 |
Correct |
472 ms |
43860 KB |
Output is correct |
61 |
Correct |
477 ms |
43892 KB |
Output is correct |
62 |
Correct |
503 ms |
43884 KB |
Output is correct |
63 |
Correct |
2239 ms |
53180 KB |
Output is correct |
64 |
Correct |
2140 ms |
53228 KB |
Output is correct |
65 |
Correct |
2148 ms |
53308 KB |
Output is correct |
66 |
Correct |
292 ms |
34556 KB |
Output is correct |
67 |
Correct |
333 ms |
43244 KB |
Output is correct |
68 |
Correct |
346 ms |
43232 KB |
Output is correct |
69 |
Correct |
353 ms |
43228 KB |
Output is correct |
70 |
Correct |
362 ms |
43252 KB |
Output is correct |
71 |
Correct |
343 ms |
43244 KB |
Output is correct |
72 |
Correct |
336 ms |
43248 KB |
Output is correct |
73 |
Correct |
348 ms |
43332 KB |
Output is correct |
74 |
Correct |
347 ms |
43232 KB |
Output is correct |
75 |
Correct |
1068 ms |
127988 KB |
Output is correct |
76 |
Correct |
889 ms |
117980 KB |
Output is correct |
77 |
Correct |
767 ms |
138604 KB |
Output is correct |
78 |
Correct |
795 ms |
120504 KB |
Output is correct |
79 |
Correct |
1352 ms |
100060 KB |
Output is correct |
80 |
Correct |
815 ms |
111316 KB |
Output is correct |
81 |
Correct |
1968 ms |
131212 KB |
Output is correct |
82 |
Correct |
1951 ms |
131080 KB |
Output is correct |
83 |
Correct |
1948 ms |
131068 KB |
Output is correct |
84 |
Correct |
2043 ms |
131460 KB |
Output is correct |
85 |
Correct |
2017 ms |
131180 KB |
Output is correct |
86 |
Correct |
1914 ms |
131180 KB |
Output is correct |
87 |
Correct |
2218 ms |
130444 KB |
Output is correct |
88 |
Execution timed out |
3079 ms |
124600 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |