#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 300005;
struct ban
{
int i;
int x, y, r;
};
bool operator<(const ban& a, const ban& b)
{
if (a.r < b.r)
return true;
if (a.r > b.r)
return false;
return a.i > b.i;
}
int n;
ban a[N];
int ans[N];
priority_queue<ban> q;
int get()
{
while (1)
{
if (q.empty())
return -1;
ban t = q.top();
q.pop();
if (!ans[t.i])
return t.i;
}
}
bool stg(long long x1, long long y1, long long r1, long long x2, long long y2, long long r2)
{
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) <= (r1 + r2) * (r1 + r2);
}
void solv0()
{
for (int i = 1; i <= n; ++i)
q.push(a[i]);
while (1)
{
int i = get();
if (i == -1)
return;
for (int j = 1; j <= n; ++j)
{
if (!ans[j])
{
if (stg(a[i].x, a[i].y, a[i].r, a[j].x, a[j].y, a[j].r))
{
ans[j] = i;
}
}
}
}
}
void solv1()
{
for (int i = 1; i <= n; ++i)
q.push(a[i]);
set<pair<int, int> > s;
for (int i = 1; i <= n; ++i)
{
s.insert(m_p(a[i].x - a[i].r, i));
s.insert(m_p(a[i].x + a[i].r, i));
}
while (1)
{
int i = get();
if (i == -1)
return;
int l = a[i].x - a[i].r;
int r = a[i].x + a[i].r;
queue<int> q;
for (set<pair<int, int> >::iterator it = s.lower_bound(m_p(l, 0)); it != s.end(); ++it)
{
if ((*it).first > r)
break;
ans[(*it).second] = i;
q.push((*it).second);
}
while (!q.empty())
{
s.erase(m_p(a[q.front()].x - a[q.front()].r, q.front()));
s.erase(m_p(a[q.front()].x + a[q.front()].r, q.front()));
q.pop();
}
}
}
int main()
{
//freopen("input.txt", "r", stdin);
cin >> n;
for (int i = 1; i <= n; ++i)
{
a[i].i = i;
cin >> a[i].x >> a[i].y >> a[i].r;
}
if (n <= 5000)
solv0();
else
solv1();
for (int i = 1; i <= n; ++i)
cout << ans[i] << ' ';
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
11 ms |
768 KB |
Output is correct |
20 |
Correct |
13 ms |
640 KB |
Output is correct |
21 |
Correct |
11 ms |
640 KB |
Output is correct |
22 |
Correct |
102 ms |
640 KB |
Output is correct |
23 |
Correct |
109 ms |
700 KB |
Output is correct |
24 |
Correct |
111 ms |
724 KB |
Output is correct |
25 |
Correct |
97 ms |
640 KB |
Output is correct |
26 |
Correct |
121 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1807 ms |
43196 KB |
Output is correct |
2 |
Correct |
1866 ms |
48976 KB |
Output is correct |
3 |
Correct |
1960 ms |
47460 KB |
Output is correct |
4 |
Correct |
1914 ms |
49896 KB |
Output is correct |
5 |
Correct |
1354 ms |
45776 KB |
Output is correct |
6 |
Correct |
1304 ms |
45968 KB |
Output is correct |
7 |
Correct |
1269 ms |
45776 KB |
Output is correct |
8 |
Correct |
1236 ms |
45904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
361 ms |
13904 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1402 ms |
40872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
11 ms |
768 KB |
Output is correct |
20 |
Correct |
13 ms |
640 KB |
Output is correct |
21 |
Correct |
11 ms |
640 KB |
Output is correct |
22 |
Correct |
102 ms |
640 KB |
Output is correct |
23 |
Correct |
109 ms |
700 KB |
Output is correct |
24 |
Correct |
111 ms |
724 KB |
Output is correct |
25 |
Correct |
97 ms |
640 KB |
Output is correct |
26 |
Correct |
121 ms |
640 KB |
Output is correct |
27 |
Incorrect |
35 ms |
1780 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
11 ms |
768 KB |
Output is correct |
20 |
Correct |
13 ms |
640 KB |
Output is correct |
21 |
Correct |
11 ms |
640 KB |
Output is correct |
22 |
Correct |
102 ms |
640 KB |
Output is correct |
23 |
Correct |
109 ms |
700 KB |
Output is correct |
24 |
Correct |
111 ms |
724 KB |
Output is correct |
25 |
Correct |
97 ms |
640 KB |
Output is correct |
26 |
Correct |
121 ms |
640 KB |
Output is correct |
27 |
Correct |
1807 ms |
43196 KB |
Output is correct |
28 |
Correct |
1866 ms |
48976 KB |
Output is correct |
29 |
Correct |
1960 ms |
47460 KB |
Output is correct |
30 |
Correct |
1914 ms |
49896 KB |
Output is correct |
31 |
Correct |
1354 ms |
45776 KB |
Output is correct |
32 |
Correct |
1304 ms |
45968 KB |
Output is correct |
33 |
Correct |
1269 ms |
45776 KB |
Output is correct |
34 |
Correct |
1236 ms |
45904 KB |
Output is correct |
35 |
Correct |
2 ms |
256 KB |
Output is correct |
36 |
Incorrect |
361 ms |
13904 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |