#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template<typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }
void debug_out() { cerr << endl; }
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cerr << ' ' << A; debug_out(B...); }
template<typename T> void mdebug_out(T* a, int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; }
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
#define debug(...) 1337
#define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T> &a) { for (auto &x : a) stream << x; return stream; }
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& a) { return stream << a.fi << ' ' << a.se; }
const int INF32 = 0x3f3f3f3f;
const int maxC = 1e9 + 7;
const int N = 300005;
int n;
ll Floor(ll a, ll b);
ll Ceil(ll a, ll b);
ll Floor(ll a, ll b)
{
if (b < 0) a = -a, b = -b;
if (a < 0) return -Ceil(-a, b);
return a / b;
}
ll Ceil(ll a, ll b)
{
if (b < 0) a = -a, b = -b;
if (a < 0) return -Floor(-a, b);
return a / b + (a % b != 0);
}
struct Circle
{
int x, y, r;
};
ll sqr(ll x) { return x * x; }
bool intersect(Circle lhs, Circle rhs)
{
return sqr(lhs.x - rhs.x) + sqr(lhs.y - rhs.y) <= sqr(lhs.r + rhs.r);
}
Circle C[N];
int ord[N], who[N];
int R;
unordered_map<ll, int> compr;
int vtx;
vector<int> grid[N];
int gt(int x, int y, bool bad = false)
{
x += maxC;
y += maxC;
ll key = x * (ll)(2 * maxC) + y;
if (compr.find(key) == compr.end())
{
if (bad) return -1;
compr.insert(mp(key, vtx));
return vtx++;
}
return compr[key];
}
void Slice(int newR)
{
compr.clear();
for (int g = 0; g < vtx; ++g)
grid[g].clear();
vtx = 0;
R = newR;
for (int i = 1; i <= n; ++i) if (!who[i])
{
int x = Floor(C[i].x, R);
int y = Floor(C[i].y, R);
int g = gt(x, y);
grid[g].push_back(i);
}
}
signed main()
{
#ifdef DEBUG
freopen("in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> C[i].x >> C[i].y >> C[i].r;
}
iota(ord, ord + n, 1);
sort(ord, ord + n, [&](int i, int j) -> bool
{
if (C[i].r != C[j].r)
return C[i].r > C[j].r;
return i < j;
});
R = 2 * INF32;
for (int t = 0; t < n; ++t)
{
int i = ord[t];
if (who[i]) continue;
if (C[i].r * 2 <= R) Slice(C[i].r);
int X = Floor(C[i].x, R);
int Y = Floor(C[i].y, R);
for (int x = X - 2; x <= X + 2; ++x)
for (int y = Y - 2; y <= Y + 2; ++y)
{
int g = gt(x, y, true);
if (g == -1) continue;
vector<int> new_grid;
for (int j : grid[g])
{
if (!who[j] && intersect(C[i], C[j]))
who[j] = i;
else
new_grid.push_back(j);
}
swap(grid[g], new_grid);
}
}
for (int i = 1; i <= n; ++i)
cout << who[i] << ' ';
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
5 ms |
7404 KB |
Output is correct |
8 |
Correct |
6 ms |
7404 KB |
Output is correct |
9 |
Correct |
5 ms |
7404 KB |
Output is correct |
10 |
Correct |
5 ms |
7404 KB |
Output is correct |
11 |
Correct |
5 ms |
7404 KB |
Output is correct |
12 |
Correct |
5 ms |
7404 KB |
Output is correct |
13 |
Correct |
6 ms |
7404 KB |
Output is correct |
14 |
Correct |
5 ms |
7404 KB |
Output is correct |
15 |
Correct |
7 ms |
7404 KB |
Output is correct |
16 |
Correct |
8 ms |
7404 KB |
Output is correct |
17 |
Correct |
6 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7404 KB |
Output is correct |
19 |
Correct |
11 ms |
7788 KB |
Output is correct |
20 |
Correct |
11 ms |
7788 KB |
Output is correct |
21 |
Correct |
11 ms |
7660 KB |
Output is correct |
22 |
Correct |
15 ms |
8044 KB |
Output is correct |
23 |
Correct |
15 ms |
8044 KB |
Output is correct |
24 |
Correct |
14 ms |
8044 KB |
Output is correct |
25 |
Correct |
15 ms |
8044 KB |
Output is correct |
26 |
Correct |
14 ms |
8044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
22336 KB |
Output is correct |
2 |
Correct |
204 ms |
22236 KB |
Output is correct |
3 |
Correct |
195 ms |
22340 KB |
Output is correct |
4 |
Correct |
187 ms |
22272 KB |
Output is correct |
5 |
Correct |
213 ms |
22124 KB |
Output is correct |
6 |
Correct |
649 ms |
31284 KB |
Output is correct |
7 |
Correct |
253 ms |
23276 KB |
Output is correct |
8 |
Correct |
300 ms |
24696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
352 ms |
20044 KB |
Output is correct |
3 |
Correct |
1425 ms |
46448 KB |
Output is correct |
4 |
Correct |
1388 ms |
46304 KB |
Output is correct |
5 |
Correct |
1308 ms |
40520 KB |
Output is correct |
6 |
Correct |
451 ms |
23952 KB |
Output is correct |
7 |
Correct |
169 ms |
16656 KB |
Output is correct |
8 |
Correct |
31 ms |
9324 KB |
Output is correct |
9 |
Correct |
1431 ms |
45732 KB |
Output is correct |
10 |
Correct |
1124 ms |
39988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1293 ms |
46172 KB |
Output is correct |
2 |
Correct |
1262 ms |
45272 KB |
Output is correct |
3 |
Correct |
381 ms |
30224 KB |
Output is correct |
4 |
Correct |
1266 ms |
45660 KB |
Output is correct |
5 |
Correct |
1326 ms |
46084 KB |
Output is correct |
6 |
Correct |
232 ms |
26348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
5 ms |
7404 KB |
Output is correct |
8 |
Correct |
6 ms |
7404 KB |
Output is correct |
9 |
Correct |
5 ms |
7404 KB |
Output is correct |
10 |
Correct |
5 ms |
7404 KB |
Output is correct |
11 |
Correct |
5 ms |
7404 KB |
Output is correct |
12 |
Correct |
5 ms |
7404 KB |
Output is correct |
13 |
Correct |
6 ms |
7404 KB |
Output is correct |
14 |
Correct |
5 ms |
7404 KB |
Output is correct |
15 |
Correct |
7 ms |
7404 KB |
Output is correct |
16 |
Correct |
8 ms |
7404 KB |
Output is correct |
17 |
Correct |
6 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7404 KB |
Output is correct |
19 |
Correct |
11 ms |
7788 KB |
Output is correct |
20 |
Correct |
11 ms |
7788 KB |
Output is correct |
21 |
Correct |
11 ms |
7660 KB |
Output is correct |
22 |
Correct |
15 ms |
8044 KB |
Output is correct |
23 |
Correct |
15 ms |
8044 KB |
Output is correct |
24 |
Correct |
14 ms |
8044 KB |
Output is correct |
25 |
Correct |
15 ms |
8044 KB |
Output is correct |
26 |
Correct |
14 ms |
8044 KB |
Output is correct |
27 |
Correct |
12 ms |
8172 KB |
Output is correct |
28 |
Correct |
11 ms |
8044 KB |
Output is correct |
29 |
Correct |
11 ms |
8044 KB |
Output is correct |
30 |
Correct |
25 ms |
8684 KB |
Output is correct |
31 |
Correct |
25 ms |
8684 KB |
Output is correct |
32 |
Correct |
24 ms |
8684 KB |
Output is correct |
33 |
Correct |
69 ms |
13280 KB |
Output is correct |
34 |
Correct |
71 ms |
13360 KB |
Output is correct |
35 |
Correct |
73 ms |
13252 KB |
Output is correct |
36 |
Correct |
349 ms |
19756 KB |
Output is correct |
37 |
Correct |
383 ms |
19784 KB |
Output is correct |
38 |
Correct |
356 ms |
19984 KB |
Output is correct |
39 |
Correct |
321 ms |
18072 KB |
Output is correct |
40 |
Correct |
319 ms |
17912 KB |
Output is correct |
41 |
Correct |
327 ms |
17792 KB |
Output is correct |
42 |
Correct |
197 ms |
18832 KB |
Output is correct |
43 |
Correct |
315 ms |
19728 KB |
Output is correct |
44 |
Correct |
321 ms |
19728 KB |
Output is correct |
45 |
Correct |
306 ms |
19728 KB |
Output is correct |
46 |
Correct |
311 ms |
19728 KB |
Output is correct |
47 |
Correct |
305 ms |
19728 KB |
Output is correct |
48 |
Correct |
316 ms |
19728 KB |
Output is correct |
49 |
Correct |
318 ms |
19728 KB |
Output is correct |
50 |
Correct |
321 ms |
19728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
5 ms |
7404 KB |
Output is correct |
8 |
Correct |
6 ms |
7404 KB |
Output is correct |
9 |
Correct |
5 ms |
7404 KB |
Output is correct |
10 |
Correct |
5 ms |
7404 KB |
Output is correct |
11 |
Correct |
5 ms |
7404 KB |
Output is correct |
12 |
Correct |
5 ms |
7404 KB |
Output is correct |
13 |
Correct |
6 ms |
7404 KB |
Output is correct |
14 |
Correct |
5 ms |
7404 KB |
Output is correct |
15 |
Correct |
7 ms |
7404 KB |
Output is correct |
16 |
Correct |
8 ms |
7404 KB |
Output is correct |
17 |
Correct |
6 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7404 KB |
Output is correct |
19 |
Correct |
11 ms |
7788 KB |
Output is correct |
20 |
Correct |
11 ms |
7788 KB |
Output is correct |
21 |
Correct |
11 ms |
7660 KB |
Output is correct |
22 |
Correct |
15 ms |
8044 KB |
Output is correct |
23 |
Correct |
15 ms |
8044 KB |
Output is correct |
24 |
Correct |
14 ms |
8044 KB |
Output is correct |
25 |
Correct |
15 ms |
8044 KB |
Output is correct |
26 |
Correct |
14 ms |
8044 KB |
Output is correct |
27 |
Correct |
198 ms |
22336 KB |
Output is correct |
28 |
Correct |
204 ms |
22236 KB |
Output is correct |
29 |
Correct |
195 ms |
22340 KB |
Output is correct |
30 |
Correct |
187 ms |
22272 KB |
Output is correct |
31 |
Correct |
213 ms |
22124 KB |
Output is correct |
32 |
Correct |
649 ms |
31284 KB |
Output is correct |
33 |
Correct |
253 ms |
23276 KB |
Output is correct |
34 |
Correct |
300 ms |
24696 KB |
Output is correct |
35 |
Correct |
5 ms |
7404 KB |
Output is correct |
36 |
Correct |
352 ms |
20044 KB |
Output is correct |
37 |
Correct |
1425 ms |
46448 KB |
Output is correct |
38 |
Correct |
1388 ms |
46304 KB |
Output is correct |
39 |
Correct |
1308 ms |
40520 KB |
Output is correct |
40 |
Correct |
451 ms |
23952 KB |
Output is correct |
41 |
Correct |
169 ms |
16656 KB |
Output is correct |
42 |
Correct |
31 ms |
9324 KB |
Output is correct |
43 |
Correct |
1431 ms |
45732 KB |
Output is correct |
44 |
Correct |
1124 ms |
39988 KB |
Output is correct |
45 |
Correct |
1293 ms |
46172 KB |
Output is correct |
46 |
Correct |
1262 ms |
45272 KB |
Output is correct |
47 |
Correct |
381 ms |
30224 KB |
Output is correct |
48 |
Correct |
1266 ms |
45660 KB |
Output is correct |
49 |
Correct |
1326 ms |
46084 KB |
Output is correct |
50 |
Correct |
232 ms |
26348 KB |
Output is correct |
51 |
Correct |
12 ms |
8172 KB |
Output is correct |
52 |
Correct |
11 ms |
8044 KB |
Output is correct |
53 |
Correct |
11 ms |
8044 KB |
Output is correct |
54 |
Correct |
25 ms |
8684 KB |
Output is correct |
55 |
Correct |
25 ms |
8684 KB |
Output is correct |
56 |
Correct |
24 ms |
8684 KB |
Output is correct |
57 |
Correct |
69 ms |
13280 KB |
Output is correct |
58 |
Correct |
71 ms |
13360 KB |
Output is correct |
59 |
Correct |
73 ms |
13252 KB |
Output is correct |
60 |
Correct |
349 ms |
19756 KB |
Output is correct |
61 |
Correct |
383 ms |
19784 KB |
Output is correct |
62 |
Correct |
356 ms |
19984 KB |
Output is correct |
63 |
Correct |
321 ms |
18072 KB |
Output is correct |
64 |
Correct |
319 ms |
17912 KB |
Output is correct |
65 |
Correct |
327 ms |
17792 KB |
Output is correct |
66 |
Correct |
197 ms |
18832 KB |
Output is correct |
67 |
Correct |
315 ms |
19728 KB |
Output is correct |
68 |
Correct |
321 ms |
19728 KB |
Output is correct |
69 |
Correct |
306 ms |
19728 KB |
Output is correct |
70 |
Correct |
311 ms |
19728 KB |
Output is correct |
71 |
Correct |
305 ms |
19728 KB |
Output is correct |
72 |
Correct |
316 ms |
19728 KB |
Output is correct |
73 |
Correct |
318 ms |
19728 KB |
Output is correct |
74 |
Correct |
321 ms |
19728 KB |
Output is correct |
75 |
Correct |
219 ms |
25000 KB |
Output is correct |
76 |
Correct |
207 ms |
24440 KB |
Output is correct |
77 |
Correct |
201 ms |
24512 KB |
Output is correct |
78 |
Correct |
203 ms |
24516 KB |
Output is correct |
79 |
Correct |
242 ms |
26208 KB |
Output is correct |
80 |
Correct |
201 ms |
24284 KB |
Output is correct |
81 |
Correct |
1368 ms |
46300 KB |
Output is correct |
82 |
Correct |
1379 ms |
46160 KB |
Output is correct |
83 |
Correct |
1351 ms |
45960 KB |
Output is correct |
84 |
Correct |
1340 ms |
46596 KB |
Output is correct |
85 |
Correct |
1350 ms |
46044 KB |
Output is correct |
86 |
Correct |
1365 ms |
46172 KB |
Output is correct |
87 |
Correct |
1334 ms |
46140 KB |
Output is correct |
88 |
Correct |
1103 ms |
39820 KB |
Output is correct |
89 |
Correct |
1088 ms |
40544 KB |
Output is correct |
90 |
Correct |
1107 ms |
39908 KB |
Output is correct |
91 |
Correct |
1084 ms |
39900 KB |
Output is correct |
92 |
Correct |
1094 ms |
40020 KB |
Output is correct |
93 |
Correct |
1253 ms |
45104 KB |
Output is correct |
94 |
Correct |
1274 ms |
45460 KB |
Output is correct |
95 |
Correct |
1253 ms |
45008 KB |
Output is correct |
96 |
Correct |
1272 ms |
45116 KB |
Output is correct |
97 |
Correct |
1203 ms |
45020 KB |
Output is correct |
98 |
Correct |
810 ms |
36640 KB |
Output is correct |
99 |
Correct |
1304 ms |
45276 KB |
Output is correct |
100 |
Correct |
1220 ms |
45020 KB |
Output is correct |
101 |
Correct |
1076 ms |
39476 KB |
Output is correct |
102 |
Correct |
1272 ms |
44820 KB |
Output is correct |
103 |
Correct |
1239 ms |
44892 KB |
Output is correct |
104 |
Correct |
1293 ms |
45020 KB |
Output is correct |
105 |
Correct |
788 ms |
42980 KB |
Output is correct |
106 |
Correct |
1070 ms |
44724 KB |
Output is correct |
107 |
Correct |
1054 ms |
44732 KB |
Output is correct |
108 |
Correct |
1095 ms |
44756 KB |
Output is correct |
109 |
Correct |
1172 ms |
44656 KB |
Output is correct |
110 |
Correct |
1070 ms |
44880 KB |
Output is correct |
111 |
Correct |
1049 ms |
44764 KB |
Output is correct |
112 |
Correct |
1199 ms |
44892 KB |
Output is correct |
113 |
Correct |
1043 ms |
44636 KB |
Output is correct |
114 |
Correct |
927 ms |
44680 KB |
Output is correct |
115 |
Correct |
1033 ms |
44764 KB |
Output is correct |
116 |
Correct |
1034 ms |
44860 KB |
Output is correct |