#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define int long long
#pragma GCC optimize("Ofast")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 3e5 + 12;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;
struct point {
int x, y, r, id;
bool operator < (const point &a) const {
if (r != a.r)
return r > a.r;
return id < a.id;
}
} a[N];
int n, res[N], bl;
set < pii > q;
vpii vals;
pii b[N];
vi m[N];
inline int getId (pii x) {
return lower_bound(all(vals), x) - vals.begin();
}
inline bool check (int i, int j) {
return (a[i].x - a[j].x) * 1ll * (a[i].x - a[j].x) + (a[i].y - a[j].y) * 1ll * (a[i].y - a[j].y) <= (a[i].r + a[j].r) * 1ll * (a[i].r + a[j].r);
}
inline void build () {
vals.clear();
q.clear();
for (int i = 1; i <= n; ++i)
if (!res[a[i].id]) {
b[i] = mp(a[i].x / bl, a[i].y / bl);
vals.pb(b[i]);
q.insert(b[i]);
}
sort(all(vals));
vals.resize(unique(all(vals)) - vals.begin());
for (int i = 0; i < sz(vals); ++i)
m[i].clear();
for (int i = 1; i <= n; ++i)
if (!res[a[i].id])
m[getId(b[i])].pb(i);
}
main () {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].r);
a[i].id = i;
}
sort(a + 1, a + 1 + n);
bl = a[1].r;
build();
for (int i = 1; i <= n; ++i)
if (!res[a[i].id]) {
if (a[i].r + a[i].r <= bl) {
bl = a[i].r;
build();
}
vector < point > V;
point Mn;
Mn.r = -inf;
for (int c = -2; c <= 2; ++c)
for (int d = -2; d <= 2; ++d) {
pii cur = mp(b[i].f + c, b[i].s + d);
if (!q.count(cur))
continue;
int z = getId(cur);
for (auto j : m[z])
if (!res[a[j].id] && check(i, j)) {
if (a[j] < Mn)
Mn = a[j];
V.pb(a[j]);
}
}
if (Mn < a[i]) {
res[a[i].id] = Mn.id;
continue;
}
res[a[i].id] = a[i].id;
for (auto j : V)
res[j.id] = a[i].id;
}
for (int i = 1; i <= n; ++i)
printf("%d ", res[i]);
}
Compilation message
circle_selection.cpp:10: warning: ignoring #pragma comment [-Wunknown-pragmas]
10 | #pragma comment(linker, "/stack:200000000")
|
circle_selection.cpp:90:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
90 | main () {
| ^
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:91:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
91 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:93:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
93 | scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:130:18: warning: 'Mn.point::id' may be used uninitialized in this function [-Wmaybe-uninitialized]
130 | res[a[i].id] = Mn.id;
| ~~~~~~~~~~~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
6 ms |
7400 KB |
Output is correct |
5 |
Correct |
5 ms |
7424 KB |
Output is correct |
6 |
Correct |
5 ms |
7424 KB |
Output is correct |
7 |
Correct |
5 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
5 ms |
7424 KB |
Output is correct |
10 |
Correct |
7 ms |
7424 KB |
Output is correct |
11 |
Correct |
6 ms |
7424 KB |
Output is correct |
12 |
Correct |
5 ms |
7424 KB |
Output is correct |
13 |
Correct |
5 ms |
7424 KB |
Output is correct |
14 |
Correct |
5 ms |
7424 KB |
Output is correct |
15 |
Correct |
7 ms |
7424 KB |
Output is correct |
16 |
Correct |
6 ms |
7424 KB |
Output is correct |
17 |
Correct |
8 ms |
7424 KB |
Output is correct |
18 |
Correct |
7 ms |
7424 KB |
Output is correct |
19 |
Correct |
9 ms |
7936 KB |
Output is correct |
20 |
Correct |
11 ms |
7936 KB |
Output is correct |
21 |
Correct |
10 ms |
7936 KB |
Output is correct |
22 |
Correct |
37 ms |
8064 KB |
Output is correct |
23 |
Correct |
34 ms |
8064 KB |
Output is correct |
24 |
Correct |
28 ms |
8064 KB |
Output is correct |
25 |
Correct |
24 ms |
8128 KB |
Output is correct |
26 |
Correct |
21 ms |
8064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
265 ms |
31716 KB |
Output is correct |
2 |
Correct |
303 ms |
29352 KB |
Output is correct |
3 |
Correct |
284 ms |
29024 KB |
Output is correct |
4 |
Correct |
242 ms |
32688 KB |
Output is correct |
5 |
Correct |
346 ms |
22948 KB |
Output is correct |
6 |
Correct |
1004 ms |
32384 KB |
Output is correct |
7 |
Correct |
433 ms |
23900 KB |
Output is correct |
8 |
Correct |
639 ms |
25464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
672 ms |
20188 KB |
Output is correct |
3 |
Correct |
2556 ms |
45240 KB |
Output is correct |
4 |
Correct |
2607 ms |
45392 KB |
Output is correct |
5 |
Correct |
2548 ms |
40756 KB |
Output is correct |
6 |
Correct |
804 ms |
23776 KB |
Output is correct |
7 |
Correct |
314 ms |
16620 KB |
Output is correct |
8 |
Correct |
49 ms |
9588 KB |
Output is correct |
9 |
Correct |
2918 ms |
44776 KB |
Output is correct |
10 |
Correct |
2177 ms |
39848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1981 ms |
45360 KB |
Output is correct |
2 |
Correct |
1486 ms |
45376 KB |
Output is correct |
3 |
Correct |
700 ms |
29020 KB |
Output is correct |
4 |
Correct |
1703 ms |
45532 KB |
Output is correct |
5 |
Correct |
1579 ms |
45400 KB |
Output is correct |
6 |
Correct |
428 ms |
24320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
6 ms |
7400 KB |
Output is correct |
5 |
Correct |
5 ms |
7424 KB |
Output is correct |
6 |
Correct |
5 ms |
7424 KB |
Output is correct |
7 |
Correct |
5 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
5 ms |
7424 KB |
Output is correct |
10 |
Correct |
7 ms |
7424 KB |
Output is correct |
11 |
Correct |
6 ms |
7424 KB |
Output is correct |
12 |
Correct |
5 ms |
7424 KB |
Output is correct |
13 |
Correct |
5 ms |
7424 KB |
Output is correct |
14 |
Correct |
5 ms |
7424 KB |
Output is correct |
15 |
Correct |
7 ms |
7424 KB |
Output is correct |
16 |
Correct |
6 ms |
7424 KB |
Output is correct |
17 |
Correct |
8 ms |
7424 KB |
Output is correct |
18 |
Correct |
7 ms |
7424 KB |
Output is correct |
19 |
Correct |
9 ms |
7936 KB |
Output is correct |
20 |
Correct |
11 ms |
7936 KB |
Output is correct |
21 |
Correct |
10 ms |
7936 KB |
Output is correct |
22 |
Correct |
37 ms |
8064 KB |
Output is correct |
23 |
Correct |
34 ms |
8064 KB |
Output is correct |
24 |
Correct |
28 ms |
8064 KB |
Output is correct |
25 |
Correct |
24 ms |
8128 KB |
Output is correct |
26 |
Correct |
21 ms |
8064 KB |
Output is correct |
27 |
Correct |
15 ms |
8464 KB |
Output is correct |
28 |
Correct |
15 ms |
8448 KB |
Output is correct |
29 |
Correct |
15 ms |
8464 KB |
Output is correct |
30 |
Correct |
41 ms |
8832 KB |
Output is correct |
31 |
Correct |
45 ms |
8832 KB |
Output is correct |
32 |
Correct |
53 ms |
8824 KB |
Output is correct |
33 |
Correct |
106 ms |
15320 KB |
Output is correct |
34 |
Correct |
92 ms |
15476 KB |
Output is correct |
35 |
Correct |
98 ms |
15596 KB |
Output is correct |
36 |
Correct |
510 ms |
20712 KB |
Output is correct |
37 |
Correct |
510 ms |
20704 KB |
Output is correct |
38 |
Correct |
529 ms |
20716 KB |
Output is correct |
39 |
Correct |
532 ms |
20472 KB |
Output is correct |
40 |
Correct |
503 ms |
20460 KB |
Output is correct |
41 |
Correct |
495 ms |
20520 KB |
Output is correct |
42 |
Correct |
478 ms |
20712 KB |
Output is correct |
43 |
Correct |
360 ms |
20528 KB |
Output is correct |
44 |
Correct |
380 ms |
20588 KB |
Output is correct |
45 |
Correct |
366 ms |
20520 KB |
Output is correct |
46 |
Correct |
385 ms |
20584 KB |
Output is correct |
47 |
Correct |
375 ms |
20520 KB |
Output is correct |
48 |
Correct |
392 ms |
20588 KB |
Output is correct |
49 |
Correct |
386 ms |
20592 KB |
Output is correct |
50 |
Correct |
413 ms |
20588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
6 ms |
7400 KB |
Output is correct |
5 |
Correct |
5 ms |
7424 KB |
Output is correct |
6 |
Correct |
5 ms |
7424 KB |
Output is correct |
7 |
Correct |
5 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
5 ms |
7424 KB |
Output is correct |
10 |
Correct |
7 ms |
7424 KB |
Output is correct |
11 |
Correct |
6 ms |
7424 KB |
Output is correct |
12 |
Correct |
5 ms |
7424 KB |
Output is correct |
13 |
Correct |
5 ms |
7424 KB |
Output is correct |
14 |
Correct |
5 ms |
7424 KB |
Output is correct |
15 |
Correct |
7 ms |
7424 KB |
Output is correct |
16 |
Correct |
6 ms |
7424 KB |
Output is correct |
17 |
Correct |
8 ms |
7424 KB |
Output is correct |
18 |
Correct |
7 ms |
7424 KB |
Output is correct |
19 |
Correct |
9 ms |
7936 KB |
Output is correct |
20 |
Correct |
11 ms |
7936 KB |
Output is correct |
21 |
Correct |
10 ms |
7936 KB |
Output is correct |
22 |
Correct |
37 ms |
8064 KB |
Output is correct |
23 |
Correct |
34 ms |
8064 KB |
Output is correct |
24 |
Correct |
28 ms |
8064 KB |
Output is correct |
25 |
Correct |
24 ms |
8128 KB |
Output is correct |
26 |
Correct |
21 ms |
8064 KB |
Output is correct |
27 |
Correct |
265 ms |
31716 KB |
Output is correct |
28 |
Correct |
303 ms |
29352 KB |
Output is correct |
29 |
Correct |
284 ms |
29024 KB |
Output is correct |
30 |
Correct |
242 ms |
32688 KB |
Output is correct |
31 |
Correct |
346 ms |
22948 KB |
Output is correct |
32 |
Correct |
1004 ms |
32384 KB |
Output is correct |
33 |
Correct |
433 ms |
23900 KB |
Output is correct |
34 |
Correct |
639 ms |
25464 KB |
Output is correct |
35 |
Correct |
5 ms |
7424 KB |
Output is correct |
36 |
Correct |
672 ms |
20188 KB |
Output is correct |
37 |
Correct |
2556 ms |
45240 KB |
Output is correct |
38 |
Correct |
2607 ms |
45392 KB |
Output is correct |
39 |
Correct |
2548 ms |
40756 KB |
Output is correct |
40 |
Correct |
804 ms |
23776 KB |
Output is correct |
41 |
Correct |
314 ms |
16620 KB |
Output is correct |
42 |
Correct |
49 ms |
9588 KB |
Output is correct |
43 |
Correct |
2918 ms |
44776 KB |
Output is correct |
44 |
Correct |
2177 ms |
39848 KB |
Output is correct |
45 |
Correct |
1981 ms |
45360 KB |
Output is correct |
46 |
Correct |
1486 ms |
45376 KB |
Output is correct |
47 |
Correct |
700 ms |
29020 KB |
Output is correct |
48 |
Correct |
1703 ms |
45532 KB |
Output is correct |
49 |
Correct |
1579 ms |
45400 KB |
Output is correct |
50 |
Correct |
428 ms |
24320 KB |
Output is correct |
51 |
Correct |
15 ms |
8464 KB |
Output is correct |
52 |
Correct |
15 ms |
8448 KB |
Output is correct |
53 |
Correct |
15 ms |
8464 KB |
Output is correct |
54 |
Correct |
41 ms |
8832 KB |
Output is correct |
55 |
Correct |
45 ms |
8832 KB |
Output is correct |
56 |
Correct |
53 ms |
8824 KB |
Output is correct |
57 |
Correct |
106 ms |
15320 KB |
Output is correct |
58 |
Correct |
92 ms |
15476 KB |
Output is correct |
59 |
Correct |
98 ms |
15596 KB |
Output is correct |
60 |
Correct |
510 ms |
20712 KB |
Output is correct |
61 |
Correct |
510 ms |
20704 KB |
Output is correct |
62 |
Correct |
529 ms |
20716 KB |
Output is correct |
63 |
Correct |
532 ms |
20472 KB |
Output is correct |
64 |
Correct |
503 ms |
20460 KB |
Output is correct |
65 |
Correct |
495 ms |
20520 KB |
Output is correct |
66 |
Correct |
478 ms |
20712 KB |
Output is correct |
67 |
Correct |
360 ms |
20528 KB |
Output is correct |
68 |
Correct |
380 ms |
20588 KB |
Output is correct |
69 |
Correct |
366 ms |
20520 KB |
Output is correct |
70 |
Correct |
385 ms |
20584 KB |
Output is correct |
71 |
Correct |
375 ms |
20520 KB |
Output is correct |
72 |
Correct |
392 ms |
20588 KB |
Output is correct |
73 |
Correct |
386 ms |
20592 KB |
Output is correct |
74 |
Correct |
413 ms |
20588 KB |
Output is correct |
75 |
Correct |
310 ms |
33680 KB |
Output is correct |
76 |
Correct |
287 ms |
30908 KB |
Output is correct |
77 |
Correct |
259 ms |
33628 KB |
Output is correct |
78 |
Correct |
259 ms |
33712 KB |
Output is correct |
79 |
Correct |
354 ms |
25564 KB |
Output is correct |
80 |
Correct |
258 ms |
33380 KB |
Output is correct |
81 |
Correct |
2517 ms |
46568 KB |
Output is correct |
82 |
Correct |
2396 ms |
46508 KB |
Output is correct |
83 |
Correct |
2422 ms |
46444 KB |
Output is correct |
84 |
Correct |
2972 ms |
46428 KB |
Output is correct |
85 |
Correct |
2302 ms |
46464 KB |
Output is correct |
86 |
Correct |
2390 ms |
46676 KB |
Output is correct |
87 |
Correct |
2766 ms |
46756 KB |
Output is correct |
88 |
Correct |
2323 ms |
46304 KB |
Output is correct |
89 |
Correct |
2079 ms |
46540 KB |
Output is correct |
90 |
Correct |
2049 ms |
45744 KB |
Output is correct |
91 |
Correct |
1950 ms |
46544 KB |
Output is correct |
92 |
Correct |
2112 ms |
45896 KB |
Output is correct |
93 |
Correct |
2067 ms |
48092 KB |
Output is correct |
94 |
Correct |
2001 ms |
47788 KB |
Output is correct |
95 |
Correct |
1847 ms |
47512 KB |
Output is correct |
96 |
Correct |
1897 ms |
47424 KB |
Output is correct |
97 |
Correct |
2961 ms |
47104 KB |
Output is correct |
98 |
Correct |
1346 ms |
37252 KB |
Output is correct |
99 |
Correct |
2036 ms |
45312 KB |
Output is correct |
100 |
Correct |
1914 ms |
45404 KB |
Output is correct |
101 |
Correct |
2070 ms |
40320 KB |
Output is correct |
102 |
Correct |
2057 ms |
45020 KB |
Output is correct |
103 |
Correct |
2668 ms |
45120 KB |
Output is correct |
104 |
Correct |
1870 ms |
45320 KB |
Output is correct |
105 |
Correct |
1818 ms |
45008 KB |
Output is correct |
106 |
Correct |
1649 ms |
43740 KB |
Output is correct |
107 |
Correct |
1397 ms |
43848 KB |
Output is correct |
108 |
Correct |
1413 ms |
43796 KB |
Output is correct |
109 |
Correct |
1405 ms |
43884 KB |
Output is correct |
110 |
Correct |
1457 ms |
43740 KB |
Output is correct |
111 |
Correct |
1519 ms |
43780 KB |
Output is correct |
112 |
Correct |
1508 ms |
44528 KB |
Output is correct |
113 |
Correct |
1550 ms |
44552 KB |
Output is correct |
114 |
Correct |
1446 ms |
44552 KB |
Output is correct |
115 |
Correct |
1433 ms |
44536 KB |
Output is correct |
116 |
Correct |
1270 ms |
44252 KB |
Output is correct |