#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
struct Circle
{
long x;
long y;
long r;
long i;
long elimBy;
long minX() const
{
return x - r;
}
long maxX() const
{
return x + r;
}
};
int main()
{
int num;
std::cin >> num;
std::vector<Circle> circles(num);
std::vector<Circle*> cByMin(num);
std::vector<Circle*> cByMax(num);
for (int i = 0; i < num; i++)
{
std::cin >> circles[i].x;
std::cin >> circles[i].y;
std::cin >> circles[i].r;
circles[i].i = i;
circles[i].elimBy = -1;
cByMin[i] = &circles[i];
cByMax[i] = &circles[i];
}
std::sort(ALL(circles), [&] (const Circle& a, const Circle& b)
{
if (a.r == b.r)
return a.i < b.i;
return a.r > b.r;
});
std::sort(ALL(cByMin), [&] (const Circle* a, const Circle* b)
{
return a->minX() < b->minX();
});
std::sort(ALL(cByMax), [&] (const Circle* a, const Circle* b)
{
return a->maxX() < b->maxX();
});
for (int i = 0; i < num; i++)
{
if (circles[i].elimBy != -1)
continue;
circles[i].elimBy = circles[i].i;
auto minB = std::lower_bound(ALL(cByMin), circles[i].minX(), [&] (Circle* c, long pos) { return c->minX() < pos; });
auto minE = std::upper_bound(ALL(cByMin), circles[i].maxX(), [&] (long pos, Circle* c) { return pos < c->minX(); });
auto maxB = std::lower_bound(ALL(cByMax), circles[i].minX(), [&] (Circle* c, long pos) { return c->maxX() <= pos; });
auto maxE = std::upper_bound(ALL(cByMax), circles[i].maxX(), [&] (long pos, Circle* c) { return pos <= c->maxX(); });
std::for_each(minB, minE, [&] (Circle* c)
{
if (c->elimBy == -1)
c->elimBy = circles[i].i;
});
std::for_each(maxB, maxE, [&] (Circle* c)
{
if (c->elimBy == -1)
c->elimBy = circles[i].i;
});
}
std::vector<long> result(num);
for (int i = 0; i < num; i++)
result[circles[i].i] = circles[i].elimBy + 1;
for (int i = 0; i < num; i++)
std::cout << result[i] << " ";
std::cout << std::endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
496 KB |
Output is correct |
3 |
Incorrect |
4 ms |
496 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
806 ms |
28012 KB |
Output is correct |
2 |
Correct |
743 ms |
34852 KB |
Output is correct |
3 |
Correct |
801 ms |
41236 KB |
Output is correct |
4 |
Correct |
780 ms |
48392 KB |
Output is correct |
5 |
Incorrect |
710 ms |
52620 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
52620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
929 ms |
60348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
496 KB |
Output is correct |
3 |
Incorrect |
4 ms |
496 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
496 KB |
Output is correct |
3 |
Incorrect |
4 ms |
496 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |