/*
DavitMarg
In pr honky-tonk,
Down in Mexico
*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <random>
#include <chrono>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 500005;
#define circle pair<pair<LL, LL>, pair<LL, int>>
#define X first.first
#define Y first.second
#define R second.first
#define I second.second
int n;
circle p[N];
LL rad;
unordered_map<LL, vector<circle>> g;
int ans[N];
bool intersect(circle a, circle b)
{
LL dx = a.X - b.X;
LL dy = a.Y - b.Y;
return (dx * dx) + (dy * dy) <= (a.R + b.R) * (a.R + b.R);
}
LL prm = 271;
LL H(pair<LL, LL> xy)
{
return ((prm * xy.first) + xy.second) % mod;
}
void changeScale()
{
g.clear();
for (int i = 1; i <= n; i++)
g[H(MP(p[i].X / rad, p[i].Y / rad))].push_back(p[i]);
}
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> p[i].X >> p[i].Y >> p[i].R;
p[i].X += mod;
p[i].Y += mod;
p[i].I = i;
rad = max(rad, p[i].R);
}
int cur = 0;
sort(p + 1, p + 1 + n, [](circle a, circle b) {
if(a.R != b.R)
return a.R > b.R;
return a.I < b.I;
});
changeScale();
for (int i = 1; i <= n; i++)
{
if (ans[p[i].I])
continue;
if (p[i].R * 2 < rad)
{
while (p[i].R * 2 < rad)
rad /= 2;
changeScale();
}
LL x = p[i].X / rad;
LL y = p[i].Y / rad;
for(int kx = x - 2; kx <= x + 2; kx++)
for (int ky = y - 2; ky <= y + 2; ky++)
{
if (g.find(H(MP(kx, ky))) == g.end())
continue;
vector<circle>& c = g[H(MP(kx, ky))];
for (int j = 0; j < c.size(); j++)
{
if (ans[c[j].I])
continue;
if(intersect(p[i], c[j]))
ans[c[j].I] = p[i].I;
}
}
}
for (int i = 1; i <= n; i++)
cout << ans[i] << " ";
cout << endl;
}
int main()
{
fastIO;
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
/*
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/
Compilation message
circle_selection.cpp: In function 'void solve()':
circle_selection.cpp:115:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for (int j = 0; j < c.size(); j++)
| ~~^~~~~~~~~~
circle_selection.cpp:84:9: warning: unused variable 'cur' [-Wunused-variable]
84 | int cur = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
0 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 |
0 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 |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
776 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
3 ms |
784 KB |
Output is correct |
22 |
Correct |
14 ms |
1108 KB |
Output is correct |
23 |
Correct |
11 ms |
980 KB |
Output is correct |
24 |
Correct |
11 ms |
1028 KB |
Output is correct |
25 |
Correct |
11 ms |
980 KB |
Output is correct |
26 |
Correct |
11 ms |
1032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
25272 KB |
Output is correct |
2 |
Correct |
127 ms |
26232 KB |
Output is correct |
3 |
Correct |
122 ms |
22556 KB |
Output is correct |
4 |
Correct |
122 ms |
26928 KB |
Output is correct |
5 |
Correct |
330 ms |
38080 KB |
Output is correct |
6 |
Correct |
973 ms |
44872 KB |
Output is correct |
7 |
Correct |
554 ms |
42692 KB |
Output is correct |
8 |
Correct |
769 ms |
44584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
392 ms |
15192 KB |
Output is correct |
3 |
Execution timed out |
3016 ms |
44004 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
829 ms |
43608 KB |
Output is correct |
2 |
Correct |
807 ms |
43892 KB |
Output is correct |
3 |
Correct |
205 ms |
31528 KB |
Output is correct |
4 |
Correct |
776 ms |
43772 KB |
Output is correct |
5 |
Correct |
752 ms |
43904 KB |
Output is correct |
6 |
Correct |
146 ms |
29388 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 |
0 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 |
0 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 |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
776 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
3 ms |
784 KB |
Output is correct |
22 |
Correct |
14 ms |
1108 KB |
Output is correct |
23 |
Correct |
11 ms |
980 KB |
Output is correct |
24 |
Correct |
11 ms |
1028 KB |
Output is correct |
25 |
Correct |
11 ms |
980 KB |
Output is correct |
26 |
Correct |
11 ms |
1032 KB |
Output is correct |
27 |
Correct |
10 ms |
1780 KB |
Output is correct |
28 |
Correct |
4 ms |
1232 KB |
Output is correct |
29 |
Correct |
4 ms |
1236 KB |
Output is correct |
30 |
Correct |
25 ms |
1720 KB |
Output is correct |
31 |
Correct |
24 ms |
1716 KB |
Output is correct |
32 |
Correct |
25 ms |
1748 KB |
Output is correct |
33 |
Correct |
40 ms |
7676 KB |
Output is correct |
34 |
Correct |
41 ms |
8516 KB |
Output is correct |
35 |
Correct |
187 ms |
15576 KB |
Output is correct |
36 |
Correct |
315 ms |
15208 KB |
Output is correct |
37 |
Correct |
325 ms |
15192 KB |
Output is correct |
38 |
Correct |
346 ms |
15224 KB |
Output is correct |
39 |
Correct |
172 ms |
11828 KB |
Output is correct |
40 |
Correct |
165 ms |
11928 KB |
Output is correct |
41 |
Correct |
171 ms |
11864 KB |
Output is correct |
42 |
Correct |
61 ms |
13420 KB |
Output is correct |
43 |
Correct |
118 ms |
14952 KB |
Output is correct |
44 |
Correct |
117 ms |
14976 KB |
Output is correct |
45 |
Correct |
162 ms |
15040 KB |
Output is correct |
46 |
Correct |
118 ms |
14980 KB |
Output is correct |
47 |
Correct |
119 ms |
14968 KB |
Output is correct |
48 |
Correct |
118 ms |
14968 KB |
Output is correct |
49 |
Correct |
134 ms |
15036 KB |
Output is correct |
50 |
Correct |
114 ms |
15036 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 |
0 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 |
0 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 |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
776 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
3 ms |
784 KB |
Output is correct |
22 |
Correct |
14 ms |
1108 KB |
Output is correct |
23 |
Correct |
11 ms |
980 KB |
Output is correct |
24 |
Correct |
11 ms |
1028 KB |
Output is correct |
25 |
Correct |
11 ms |
980 KB |
Output is correct |
26 |
Correct |
11 ms |
1032 KB |
Output is correct |
27 |
Correct |
127 ms |
25272 KB |
Output is correct |
28 |
Correct |
127 ms |
26232 KB |
Output is correct |
29 |
Correct |
122 ms |
22556 KB |
Output is correct |
30 |
Correct |
122 ms |
26928 KB |
Output is correct |
31 |
Correct |
330 ms |
38080 KB |
Output is correct |
32 |
Correct |
973 ms |
44872 KB |
Output is correct |
33 |
Correct |
554 ms |
42692 KB |
Output is correct |
34 |
Correct |
769 ms |
44584 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
392 ms |
15192 KB |
Output is correct |
37 |
Execution timed out |
3016 ms |
44004 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |