#include <bits/stdc++.h>
#define lli long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N = 3e5 + 5;
const int INF = 1e9 + 500;
const int SHIFT = 1e9 + 2;
vector<array<int, 3> > p;
vector<set<array<int, 2> > > st;
vector<int> xc;
int rc = 0;
set<pair<int, int> > S;
lli sqr(int x) {
return 1ll * x * x;
}
bool query(int x, int y) {
return sqr(p[x][1] - p[y][1]) + sqr(p[x][2] - p[y][2]) <= sqr(p[x][0] + p[y][0]);
}
void printp(int ind) {
cout << "ind: " << ind + 1 << " rad:" << p[ind][0] << " x:" << p[ind][1] << " y:" << p[ind][2] << "\n";
}
void rescale(int r) {
rc = r;
st.clear();
xc.clear();
for(auto z : S) {
int j = z.second;
auto &c = p[j];
for(int i = -2; i <= 2; i++) {
xc.pb(c[1] / r + i);
}
}
sort(all(xc));
xc.resize(unique(all(xc)) - xc.begin());
st.assign(xc.size(), set<array<int, 2> >());
for(auto z : S) {
int i = z.second;
auto &c = p[i];
int xx = lower_bound(all(xc), c[1] / r) - xc.begin();
st[xx].insert({c[2] / r, i});
}
// for(int i = 0; i < xc.size(); i++) {
// cout << "i:" << i << " row:" << xc[i] << "\n";
// for(auto c : st[i]) {
// cout << "c0:" << c[0] << " c1:" << c[1] << "|| ";
// }
// cout << "\n";
// }
}
int n;
vector<int> ans(N, 0);
void eliminate() {
int ind = (*S.begin()).second;
ans[ind] = ind;
if(p[ind][0] * 2 < rc) {
rescale(p[ind][0]);
}
S.erase(S.begin());
if(S.size() == 0) return;
int xx = lower_bound(all(xc), p[ind][1] / rc) - xc.begin();
int yy = p[ind][2] / rc;
st[xx].erase({yy, ind});
// printp(ind);
// cout << "xx:" << xx << " yy:" << yy << "\n";
// cout << "eliminates: ";
for(int i = xx - 2; i <= xx + 2; i++) {
for(auto j = st[i].lower_bound({yy - 2, 0}); j != st[i].end() && (*j)[0] <= yy + 2; ) {
// printp((*j)[1]);
if(query((*j)[1], ind)) {
// cout << "killed\n";
ans[(*j)[1]] = ind;
S.erase({-p[(*j)[1]][0], (*j)[1]});
j = st[i].erase(j);
}
else {
j++;
}
}
}
// cout << "\n\n";
}
void solve() {
cin >> n;
p.resize(n);
REP(i, n) {
cin >> p[i][1] >> p[i][2] >> p[i][0];
p[i][1] += SHIFT;
p[i][2] += SHIFT;
S.insert({-p[i][0], i});
}
// cout << "zort" << endl;
rescale(-(*S.begin()).first);
// cout << "zort2" << endl;
while(S.size()) {
eliminate();
}
REP(i, n) {
cout << ans[i] + 1 << " ";
}
cout << "\n";
}
signed main() {
fastio();
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
1640 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
1624 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1624 KB |
Output is correct |
16 |
Correct |
2 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
1628 KB |
Output is correct |
19 |
Correct |
5 ms |
2392 KB |
Output is correct |
20 |
Correct |
6 ms |
2420 KB |
Output is correct |
21 |
Correct |
5 ms |
2360 KB |
Output is correct |
22 |
Correct |
8 ms |
2868 KB |
Output is correct |
23 |
Correct |
8 ms |
2348 KB |
Output is correct |
24 |
Correct |
8 ms |
2908 KB |
Output is correct |
25 |
Correct |
9 ms |
3420 KB |
Output is correct |
26 |
Correct |
10 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
590 ms |
41624 KB |
Output is correct |
2 |
Correct |
585 ms |
41884 KB |
Output is correct |
3 |
Correct |
674 ms |
41652 KB |
Output is correct |
4 |
Correct |
543 ms |
42368 KB |
Output is correct |
5 |
Correct |
613 ms |
40152 KB |
Output is correct |
6 |
Correct |
687 ms |
51800 KB |
Output is correct |
7 |
Correct |
655 ms |
43288 KB |
Output is correct |
8 |
Correct |
706 ms |
43692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
196 ms |
14416 KB |
Output is correct |
3 |
Correct |
853 ms |
41140 KB |
Output is correct |
4 |
Correct |
841 ms |
41748 KB |
Output is correct |
5 |
Correct |
1053 ms |
38832 KB |
Output is correct |
6 |
Correct |
374 ms |
21692 KB |
Output is correct |
7 |
Correct |
153 ms |
12200 KB |
Output is correct |
8 |
Correct |
23 ms |
4820 KB |
Output is correct |
9 |
Correct |
1087 ms |
48272 KB |
Output is correct |
10 |
Correct |
1241 ms |
49896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
455 ms |
44936 KB |
Output is correct |
2 |
Correct |
506 ms |
111996 KB |
Output is correct |
3 |
Correct |
561 ms |
41904 KB |
Output is correct |
4 |
Correct |
478 ms |
91284 KB |
Output is correct |
5 |
Correct |
514 ms |
100888 KB |
Output is correct |
6 |
Correct |
518 ms |
41652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
1640 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
1624 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1624 KB |
Output is correct |
16 |
Correct |
2 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
1628 KB |
Output is correct |
19 |
Correct |
5 ms |
2392 KB |
Output is correct |
20 |
Correct |
6 ms |
2420 KB |
Output is correct |
21 |
Correct |
5 ms |
2360 KB |
Output is correct |
22 |
Correct |
8 ms |
2868 KB |
Output is correct |
23 |
Correct |
8 ms |
2348 KB |
Output is correct |
24 |
Correct |
8 ms |
2908 KB |
Output is correct |
25 |
Correct |
9 ms |
3420 KB |
Output is correct |
26 |
Correct |
10 ms |
3164 KB |
Output is correct |
27 |
Correct |
11 ms |
3032 KB |
Output is correct |
28 |
Correct |
12 ms |
3032 KB |
Output is correct |
29 |
Correct |
13 ms |
3032 KB |
Output is correct |
30 |
Correct |
17 ms |
3032 KB |
Output is correct |
31 |
Correct |
16 ms |
4084 KB |
Output is correct |
32 |
Correct |
16 ms |
4056 KB |
Output is correct |
33 |
Correct |
120 ms |
17676 KB |
Output is correct |
34 |
Correct |
128 ms |
17860 KB |
Output is correct |
35 |
Correct |
136 ms |
17604 KB |
Output is correct |
36 |
Correct |
194 ms |
20860 KB |
Output is correct |
37 |
Correct |
194 ms |
20660 KB |
Output is correct |
38 |
Correct |
193 ms |
19860 KB |
Output is correct |
39 |
Correct |
690 ms |
15756 KB |
Output is correct |
40 |
Correct |
683 ms |
15808 KB |
Output is correct |
41 |
Correct |
643 ms |
15812 KB |
Output is correct |
42 |
Correct |
150 ms |
16084 KB |
Output is correct |
43 |
Correct |
149 ms |
37320 KB |
Output is correct |
44 |
Correct |
148 ms |
37284 KB |
Output is correct |
45 |
Correct |
152 ms |
37128 KB |
Output is correct |
46 |
Correct |
153 ms |
37316 KB |
Output is correct |
47 |
Correct |
149 ms |
37312 KB |
Output is correct |
48 |
Correct |
147 ms |
37312 KB |
Output is correct |
49 |
Correct |
148 ms |
37320 KB |
Output is correct |
50 |
Correct |
147 ms |
37312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
1640 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
1624 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1624 KB |
Output is correct |
16 |
Correct |
2 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
1628 KB |
Output is correct |
19 |
Correct |
5 ms |
2392 KB |
Output is correct |
20 |
Correct |
6 ms |
2420 KB |
Output is correct |
21 |
Correct |
5 ms |
2360 KB |
Output is correct |
22 |
Correct |
8 ms |
2868 KB |
Output is correct |
23 |
Correct |
8 ms |
2348 KB |
Output is correct |
24 |
Correct |
8 ms |
2908 KB |
Output is correct |
25 |
Correct |
9 ms |
3420 KB |
Output is correct |
26 |
Correct |
10 ms |
3164 KB |
Output is correct |
27 |
Correct |
590 ms |
41624 KB |
Output is correct |
28 |
Correct |
585 ms |
41884 KB |
Output is correct |
29 |
Correct |
674 ms |
41652 KB |
Output is correct |
30 |
Correct |
543 ms |
42368 KB |
Output is correct |
31 |
Correct |
613 ms |
40152 KB |
Output is correct |
32 |
Correct |
687 ms |
51800 KB |
Output is correct |
33 |
Correct |
655 ms |
43288 KB |
Output is correct |
34 |
Correct |
706 ms |
43692 KB |
Output is correct |
35 |
Correct |
1 ms |
1624 KB |
Output is correct |
36 |
Correct |
196 ms |
14416 KB |
Output is correct |
37 |
Correct |
853 ms |
41140 KB |
Output is correct |
38 |
Correct |
841 ms |
41748 KB |
Output is correct |
39 |
Correct |
1053 ms |
38832 KB |
Output is correct |
40 |
Correct |
374 ms |
21692 KB |
Output is correct |
41 |
Correct |
153 ms |
12200 KB |
Output is correct |
42 |
Correct |
23 ms |
4820 KB |
Output is correct |
43 |
Correct |
1087 ms |
48272 KB |
Output is correct |
44 |
Correct |
1241 ms |
49896 KB |
Output is correct |
45 |
Correct |
455 ms |
44936 KB |
Output is correct |
46 |
Correct |
506 ms |
111996 KB |
Output is correct |
47 |
Correct |
561 ms |
41904 KB |
Output is correct |
48 |
Correct |
478 ms |
91284 KB |
Output is correct |
49 |
Correct |
514 ms |
100888 KB |
Output is correct |
50 |
Correct |
518 ms |
41652 KB |
Output is correct |
51 |
Correct |
11 ms |
3032 KB |
Output is correct |
52 |
Correct |
12 ms |
3032 KB |
Output is correct |
53 |
Correct |
13 ms |
3032 KB |
Output is correct |
54 |
Correct |
17 ms |
3032 KB |
Output is correct |
55 |
Correct |
16 ms |
4084 KB |
Output is correct |
56 |
Correct |
16 ms |
4056 KB |
Output is correct |
57 |
Correct |
120 ms |
17676 KB |
Output is correct |
58 |
Correct |
128 ms |
17860 KB |
Output is correct |
59 |
Correct |
136 ms |
17604 KB |
Output is correct |
60 |
Correct |
194 ms |
20860 KB |
Output is correct |
61 |
Correct |
194 ms |
20660 KB |
Output is correct |
62 |
Correct |
193 ms |
19860 KB |
Output is correct |
63 |
Correct |
690 ms |
15756 KB |
Output is correct |
64 |
Correct |
683 ms |
15808 KB |
Output is correct |
65 |
Correct |
643 ms |
15812 KB |
Output is correct |
66 |
Correct |
150 ms |
16084 KB |
Output is correct |
67 |
Correct |
149 ms |
37320 KB |
Output is correct |
68 |
Correct |
148 ms |
37284 KB |
Output is correct |
69 |
Correct |
152 ms |
37128 KB |
Output is correct |
70 |
Correct |
153 ms |
37316 KB |
Output is correct |
71 |
Correct |
149 ms |
37312 KB |
Output is correct |
72 |
Correct |
147 ms |
37312 KB |
Output is correct |
73 |
Correct |
148 ms |
37320 KB |
Output is correct |
74 |
Correct |
147 ms |
37312 KB |
Output is correct |
75 |
Correct |
649 ms |
50520 KB |
Output is correct |
76 |
Correct |
572 ms |
51228 KB |
Output is correct |
77 |
Correct |
524 ms |
51632 KB |
Output is correct |
78 |
Correct |
544 ms |
51372 KB |
Output is correct |
79 |
Correct |
728 ms |
48512 KB |
Output is correct |
80 |
Correct |
562 ms |
51376 KB |
Output is correct |
81 |
Correct |
885 ms |
49932 KB |
Output is correct |
82 |
Correct |
921 ms |
50576 KB |
Output is correct |
83 |
Correct |
966 ms |
49328 KB |
Output is correct |
84 |
Correct |
859 ms |
48052 KB |
Output is correct |
85 |
Correct |
956 ms |
50180 KB |
Output is correct |
86 |
Correct |
891 ms |
52676 KB |
Output is correct |
87 |
Correct |
984 ms |
48296 KB |
Output is correct |
88 |
Correct |
2616 ms |
46140 KB |
Output is correct |
89 |
Correct |
2697 ms |
44820 KB |
Output is correct |
90 |
Correct |
2768 ms |
44504 KB |
Output is correct |
91 |
Correct |
2558 ms |
45652 KB |
Output is correct |
92 |
Correct |
2648 ms |
44512 KB |
Output is correct |
93 |
Correct |
785 ms |
115068 KB |
Output is correct |
94 |
Correct |
860 ms |
50272 KB |
Output is correct |
95 |
Correct |
815 ms |
116968 KB |
Output is correct |
96 |
Correct |
823 ms |
106136 KB |
Output is correct |
97 |
Correct |
973 ms |
48464 KB |
Output is correct |
98 |
Correct |
857 ms |
62852 KB |
Output is correct |
99 |
Correct |
859 ms |
117012 KB |
Output is correct |
100 |
Correct |
585 ms |
118704 KB |
Output is correct |
101 |
Correct |
902 ms |
55468 KB |
Output is correct |
102 |
Correct |
870 ms |
105588 KB |
Output is correct |
103 |
Correct |
1068 ms |
48384 KB |
Output is correct |
104 |
Correct |
850 ms |
117684 KB |
Output is correct |
105 |
Correct |
668 ms |
47584 KB |
Output is correct |
106 |
Correct |
520 ms |
73984 KB |
Output is correct |
107 |
Correct |
515 ms |
74484 KB |
Output is correct |
108 |
Correct |
524 ms |
74928 KB |
Output is correct |
109 |
Correct |
533 ms |
74772 KB |
Output is correct |
110 |
Correct |
540 ms |
73624 KB |
Output is correct |
111 |
Correct |
518 ms |
73252 KB |
Output is correct |
112 |
Correct |
519 ms |
73656 KB |
Output is correct |
113 |
Correct |
533 ms |
74972 KB |
Output is correct |
114 |
Correct |
512 ms |
74812 KB |
Output is correct |
115 |
Correct |
529 ms |
74364 KB |
Output is correct |
116 |
Correct |
533 ms |
99260 KB |
Output is correct |