#pragma GCC optimize("O3,inline")
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
using ll = long long;
const ll MOD = 1e9+7;
const int MAX_N = 3e5+5;
int n;
struct Node
{
ll x, y, r;
int p;
bool visited;
} A[MAX_N];
struct LLNode
{
int idx;
LLNode* next = nullptr;
inline LLNode()
{
}
inline LLNode(const int & val)
: idx(val)
{
}
} LLNodes[MAX_N];
int llcounter = 0;
inline LLNode* getLLNode()
{
return &LLNodes[llcounter++];
}
int dup;
struct Quad;
inline Quad* getQuadNode();
struct Quad
{
ll l, r, bot, top;
array<Quad*, 4> childs = {};
LLNode* llnode = nullptr;
int sz;
inline Quad()
{
}
inline Quad(const ll & _l, const ll & _r, const ll & _bot, const ll & _top)
: l(_l), r(_r), bot(_bot), top(_top)
{
sz = 0;
}
void add(const ll & x, const ll & y, const int & idx)
{
if(x < l || x > r || y < bot || y > top) {
return;
}
sz++;
// cerr << "l = " << l << ", r = " << r << ", "
// << "bot = " << bot << ", top = " << top << "\n";
if(l == r && bot == top) {
if(llnode == nullptr) {
llnode = getLLNode();
llnode->idx = idx;
}
else {
//dup++;
LLNode* temp = getLLNode();
temp->idx = idx;
temp->next = llnode;
llnode = temp;
}
}
else {
ll midH, midV;
midH = l+(r-l)/2;
midV = bot+(top-bot)/2;
if(l != r && top != bot) {
if(childs[0] == nullptr && !(x < l || x > midH || y < bot || y > midV)) {
childs[0] = getQuadNode();
childs[0]->l = l;
childs[0]->r = midH;
childs[0]->bot = bot;
childs[0]->top = midV;
}
else if(childs[1] == nullptr && !(x < midH+1 || x > r || y < bot || y > midV)) {
childs[1] = getQuadNode();
childs[1]->l = midH+1;
childs[1]->r = r;
childs[1]->bot = bot;
childs[1]->top = midV;
}
else if(childs[2] == nullptr && !(x < l || x > midH || y < midV+1 || y > top)) {
childs[2] = getQuadNode();
childs[2]->l = l;
childs[2]->r = midH;
childs[2]->bot = midV+1;
childs[2]->top = top;
}
else if(childs[3] == nullptr && !(x < midH+1 || x > r || y < midV+1 || y > top)) {
childs[3] = getQuadNode();
childs[3]->l = midH+1;
childs[3]->r = r;
childs[3]->bot = midV+1;
childs[3]->top = top;
}
}
else if(l != r) {
if(childs[0] == nullptr && !(x < l || x > midH || y < bot || y > top)) {
childs[0] = getQuadNode();
childs[0]->l = l;
childs[0]->r = midH;
childs[0]->bot = bot;
childs[0]->top = top;
}
else if(childs[1] == nullptr && !(x < midH+1 || x > r || y < bot || y > top)) {
childs[1] = getQuadNode();
childs[1]->l = midH+1;
childs[1]->r = r;
childs[1]->bot = bot;
childs[1]->top = top;
}
}
else if(top != bot) {
if(childs[0] == nullptr && !(x < l || x > r || y < bot || y > midV)) {
childs[0] = getQuadNode();
childs[0]->l = l;
childs[0]->r = r;
childs[0]->bot = bot;
childs[0]->top = midV;
}
else if(childs[1] == nullptr && !(x < l || x > r || y < midV+1 || y > top)) {
childs[1] = getQuadNode();
childs[1]->l = l;
childs[1]->r = r;
childs[1]->bot = midV+1;
childs[1]->top = top;
}
}
for(int k = 0; k < 4; k++) {
if(childs[k] != nullptr) {
childs[k]->add(x, y, idx);
}
}
}
}
void setInRange(const ll & x, const ll & y, const ll & radius, const int & idx)
{
if(x+2*radius < l || x-2*radius > r || y+2*radius < bot || y-2*radius > top || sz == 0) {
return;
}
// cerr << "l = " << l << ", r = " << r << ", "
// << "bot = " << bot << ", top = " << top << "\n";
if(l == r && bot == top) {
while(llnode != nullptr &&
(A[idx].r+A[llnode->idx].r)*(A[idx].r+A[llnode->idx].r)
>= llabs(A[idx].x-A[llnode->idx].x)*llabs(A[idx].x-A[llnode->idx].x)
+llabs(A[idx].y-A[llnode->idx].y)*llabs(A[idx].y-A[llnode->idx].y)) {
A[llnode->idx].p = idx;
A[llnode->idx].visited = true;
sz--;
llnode = llnode->next;
}
return;
}
int cnt = 0;
for(int k = 0; k < 4; k++) {
if(childs[k] != nullptr) {
childs[k]->setInRange(x, y, radius, idx);
cnt += childs[k]->sz;
}
}
sz = cnt;
}
} QuadNodes[MAX_N*20];
int quadcounter = 0;
inline Quad* getQuadNode()
{
return &QuadNodes[quadcounter++];
}
Quad Q(-1000000000, 1000000000, -1000000000, 1000000000);
inline int nextInt()
{
int c = getchar();
while (c != '-' && (c < '0' || c > '9')) {
c = getchar();
}
int x = 0;
bool neg = false;
if (c == '-') {
neg = true;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x*10+(c-'0');
c = getchar();
}
if (neg)
return -x;
return x;
}
int main()
{
//auto stop = steady_clock::now();
n = nextInt();
for(int i = 0; i < n; i++) {
A[i].x = nextInt();
A[i].y = nextInt();
A[i].r = nextInt();
}
//cerr << "Exec: " << duration_cast<milliseconds>(steady_clock::now()-stop).count() << " ms\n";
vector<int> I(n);
iota(I.begin(), I.end(), 0);
sort(I.begin(), I.end(),
[&](int a, int b)
{
return A[a].r > A[b].r || (A[a].r == A[b].r && a < b);
});
for(int i = n-1; i >= 0; i--) {
int idx = I[i];
//cerr << i << " started\n";
Q.add(A[idx].x, A[idx].y, idx);
//cerr << i << " finished\n";
}
for(int i = 0; i < n; i++) {
int idx = I[i];
if(A[idx].visited) continue;
Q.setInRange(A[idx].x, A[idx].y, A[idx].r, idx);
}
for(int i = 0; i < n; i++) {
cout << 1+A[i].p << " ";
}
cout << "\n";
// cerr << "Dupe: " << dup << "\n";
// cerr << "Exec: " << duration_cast<milliseconds>(steady_clock::now()-stop).count() << " ms\n";
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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
474548 KB |
Output is correct |
2 |
Correct |
164 ms |
474628 KB |
Output is correct |
3 |
Correct |
164 ms |
474568 KB |
Output is correct |
4 |
Correct |
161 ms |
474564 KB |
Output is correct |
5 |
Correct |
164 ms |
474636 KB |
Output is correct |
6 |
Correct |
161 ms |
474568 KB |
Output is correct |
7 |
Correct |
161 ms |
474564 KB |
Output is correct |
8 |
Correct |
163 ms |
474580 KB |
Output is correct |
9 |
Correct |
161 ms |
474656 KB |
Output is correct |
10 |
Correct |
165 ms |
474564 KB |
Output is correct |
11 |
Correct |
161 ms |
474592 KB |
Output is correct |
12 |
Correct |
165 ms |
474564 KB |
Output is correct |
13 |
Correct |
164 ms |
474580 KB |
Output is correct |
14 |
Correct |
171 ms |
474564 KB |
Output is correct |
15 |
Correct |
160 ms |
474540 KB |
Output is correct |
16 |
Correct |
165 ms |
474616 KB |
Output is correct |
17 |
Correct |
164 ms |
474636 KB |
Output is correct |
18 |
Correct |
163 ms |
474584 KB |
Output is correct |
19 |
Correct |
178 ms |
474824 KB |
Output is correct |
20 |
Correct |
171 ms |
474836 KB |
Output is correct |
21 |
Correct |
172 ms |
474776 KB |
Output is correct |
22 |
Correct |
175 ms |
474820 KB |
Output is correct |
23 |
Correct |
173 ms |
474812 KB |
Output is correct |
24 |
Correct |
183 ms |
474900 KB |
Output is correct |
25 |
Correct |
175 ms |
474820 KB |
Output is correct |
26 |
Correct |
177 ms |
474792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
822 ms |
487320 KB |
Output is correct |
2 |
Correct |
852 ms |
487364 KB |
Output is correct |
3 |
Correct |
854 ms |
487004 KB |
Output is correct |
4 |
Correct |
822 ms |
487288 KB |
Output is correct |
5 |
Correct |
609 ms |
487196 KB |
Output is correct |
6 |
Correct |
853 ms |
487136 KB |
Output is correct |
7 |
Correct |
711 ms |
487108 KB |
Output is correct |
8 |
Correct |
750 ms |
487176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
474624 KB |
Output is correct |
2 |
Correct |
502 ms |
478696 KB |
Output is correct |
3 |
Runtime error |
1002 ms |
982484 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
941 ms |
983804 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
474548 KB |
Output is correct |
2 |
Correct |
164 ms |
474628 KB |
Output is correct |
3 |
Correct |
164 ms |
474568 KB |
Output is correct |
4 |
Correct |
161 ms |
474564 KB |
Output is correct |
5 |
Correct |
164 ms |
474636 KB |
Output is correct |
6 |
Correct |
161 ms |
474568 KB |
Output is correct |
7 |
Correct |
161 ms |
474564 KB |
Output is correct |
8 |
Correct |
163 ms |
474580 KB |
Output is correct |
9 |
Correct |
161 ms |
474656 KB |
Output is correct |
10 |
Correct |
165 ms |
474564 KB |
Output is correct |
11 |
Correct |
161 ms |
474592 KB |
Output is correct |
12 |
Correct |
165 ms |
474564 KB |
Output is correct |
13 |
Correct |
164 ms |
474580 KB |
Output is correct |
14 |
Correct |
171 ms |
474564 KB |
Output is correct |
15 |
Correct |
160 ms |
474540 KB |
Output is correct |
16 |
Correct |
165 ms |
474616 KB |
Output is correct |
17 |
Correct |
164 ms |
474636 KB |
Output is correct |
18 |
Correct |
163 ms |
474584 KB |
Output is correct |
19 |
Correct |
178 ms |
474824 KB |
Output is correct |
20 |
Correct |
171 ms |
474836 KB |
Output is correct |
21 |
Correct |
172 ms |
474776 KB |
Output is correct |
22 |
Correct |
175 ms |
474820 KB |
Output is correct |
23 |
Correct |
173 ms |
474812 KB |
Output is correct |
24 |
Correct |
183 ms |
474900 KB |
Output is correct |
25 |
Correct |
175 ms |
474820 KB |
Output is correct |
26 |
Correct |
177 ms |
474792 KB |
Output is correct |
27 |
Correct |
188 ms |
475040 KB |
Output is correct |
28 |
Correct |
186 ms |
475016 KB |
Output is correct |
29 |
Correct |
186 ms |
474928 KB |
Output is correct |
30 |
Correct |
191 ms |
474940 KB |
Output is correct |
31 |
Correct |
194 ms |
475076 KB |
Output is correct |
32 |
Correct |
190 ms |
475024 KB |
Output is correct |
33 |
Correct |
402 ms |
478732 KB |
Output is correct |
34 |
Correct |
408 ms |
478696 KB |
Output is correct |
35 |
Correct |
424 ms |
478660 KB |
Output is correct |
36 |
Correct |
485 ms |
478752 KB |
Output is correct |
37 |
Correct |
491 ms |
478792 KB |
Output is correct |
38 |
Correct |
489 ms |
478660 KB |
Output is correct |
39 |
Correct |
1215 ms |
478788 KB |
Output is correct |
40 |
Correct |
1258 ms |
478728 KB |
Output is correct |
41 |
Correct |
1250 ms |
478696 KB |
Output is correct |
42 |
Correct |
394 ms |
478624 KB |
Output is correct |
43 |
Correct |
463 ms |
478688 KB |
Output is correct |
44 |
Correct |
478 ms |
478684 KB |
Output is correct |
45 |
Correct |
468 ms |
478712 KB |
Output is correct |
46 |
Correct |
461 ms |
478660 KB |
Output is correct |
47 |
Correct |
465 ms |
478648 KB |
Output is correct |
48 |
Correct |
469 ms |
478656 KB |
Output is correct |
49 |
Correct |
464 ms |
478720 KB |
Output is correct |
50 |
Correct |
484 ms |
478800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
474548 KB |
Output is correct |
2 |
Correct |
164 ms |
474628 KB |
Output is correct |
3 |
Correct |
164 ms |
474568 KB |
Output is correct |
4 |
Correct |
161 ms |
474564 KB |
Output is correct |
5 |
Correct |
164 ms |
474636 KB |
Output is correct |
6 |
Correct |
161 ms |
474568 KB |
Output is correct |
7 |
Correct |
161 ms |
474564 KB |
Output is correct |
8 |
Correct |
163 ms |
474580 KB |
Output is correct |
9 |
Correct |
161 ms |
474656 KB |
Output is correct |
10 |
Correct |
165 ms |
474564 KB |
Output is correct |
11 |
Correct |
161 ms |
474592 KB |
Output is correct |
12 |
Correct |
165 ms |
474564 KB |
Output is correct |
13 |
Correct |
164 ms |
474580 KB |
Output is correct |
14 |
Correct |
171 ms |
474564 KB |
Output is correct |
15 |
Correct |
160 ms |
474540 KB |
Output is correct |
16 |
Correct |
165 ms |
474616 KB |
Output is correct |
17 |
Correct |
164 ms |
474636 KB |
Output is correct |
18 |
Correct |
163 ms |
474584 KB |
Output is correct |
19 |
Correct |
178 ms |
474824 KB |
Output is correct |
20 |
Correct |
171 ms |
474836 KB |
Output is correct |
21 |
Correct |
172 ms |
474776 KB |
Output is correct |
22 |
Correct |
175 ms |
474820 KB |
Output is correct |
23 |
Correct |
173 ms |
474812 KB |
Output is correct |
24 |
Correct |
183 ms |
474900 KB |
Output is correct |
25 |
Correct |
175 ms |
474820 KB |
Output is correct |
26 |
Correct |
177 ms |
474792 KB |
Output is correct |
27 |
Correct |
822 ms |
487320 KB |
Output is correct |
28 |
Correct |
852 ms |
487364 KB |
Output is correct |
29 |
Correct |
854 ms |
487004 KB |
Output is correct |
30 |
Correct |
822 ms |
487288 KB |
Output is correct |
31 |
Correct |
609 ms |
487196 KB |
Output is correct |
32 |
Correct |
853 ms |
487136 KB |
Output is correct |
33 |
Correct |
711 ms |
487108 KB |
Output is correct |
34 |
Correct |
750 ms |
487176 KB |
Output is correct |
35 |
Correct |
162 ms |
474624 KB |
Output is correct |
36 |
Correct |
502 ms |
478696 KB |
Output is correct |
37 |
Runtime error |
1002 ms |
982484 KB |
Execution killed with signal 11 |
38 |
Halted |
0 ms |
0 KB |
- |