#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#pragma warning (disable: 4996)
struct Node {
int val, num, l, r;
};
class SegmentTree {
public:
vector<Node>vec; vector<int>V; long long lx, ly, rx, ry;
void init() {
vec.push_back(Node{ 0, 0, -1, -1 });
}
void add(long long px, long long py, int NN) {
int cx = 0;
for (int i = 61; i >= 0; i--) {
vec[cx].val += 1;
if (i >= 31) {
int dep = i - 31;
if (px >= (1LL << dep)) {
if (vec[cx].r == -1) { vec[cx].r = vec.size(); vec.push_back(Node{ 0, 0, -1,-1 }); }
cx = vec[cx].r; px -= (1LL << dep);
}
else {
if (vec[cx].l == -1) { vec[cx].l = vec.size(); vec.push_back(Node{ 0, 0, -1,-1 }); }
cx = vec[cx].l;
}
}
else {
int dep = i;
if (py >= (1LL << dep)) {
if (vec[cx].r == -1) { vec[cx].r = vec.size(); vec.push_back(Node{ 0, 0, -1,-1 }); }
cx = vec[cx].r; py -= (1LL << dep);
}
else {
if (vec[cx].l == -1) { vec[cx].l = vec.size(); vec.push_back(Node{ 0, 0, -1,-1 }); }
cx = vec[cx].l;
}
}
}
vec[cx].val++; vec[cx].num = NN;
}
void lose(long long px, long long py, int NN) {
int cx = 0;
for (int i = 61; i >= 0; i--) {
vec[cx].val -= 1;
if (i >= 31) {
int dep = i - 31;
if (px >= (1LL << dep)) {
if (vec[cx].r == -1) { vec[cx].r = vec.size(); vec.push_back(Node{ 0, 0, -1,-1 }); }
cx = vec[cx].r; px -= (1LL << dep);
}
else {
if (vec[cx].l == -1) { vec[cx].l = vec.size(); vec.push_back(Node{ 0, 0, -1,-1 }); }
cx = vec[cx].l;
}
}
else {
int dep = i;
if (py >= (1LL << dep)) {
if (vec[cx].r == -1) { vec[cx].r = vec.size(); vec.push_back(Node{ 0, 0, -1,-1 }); }
cx = vec[cx].r; py -= (1LL << dep);
}
else {
if (vec[cx].l == -1) { vec[cx].l = vec.size(); vec.push_back(Node{ 0, 0, -1,-1 }); }
cx = vec[cx].l;
}
}
}
vec[cx].val--; vec[cx].num = 0;
}
void query_(long long ax, long long ay, long long bx, long long by, int dep, int u) {
if (vec[u].val == 0) return;
if (rx <= ax || bx <= lx || ry <= ay || by <= ly) return;
if (dep == 0) {
V.push_back(vec[u].num);
return;
}
if (dep >= 32) {
if (vec[u].l >= 0) query_(ax, ay, (ax + bx) >> 1, by, dep - 1, vec[u].l);
if (vec[u].r >= 0) query_((ax + bx) >> 1, ay, bx, by, dep - 1, vec[u].r);
}
else {
if (vec[u].l >= 0) query_(ax, ay, bx, (ay + by) >> 1, dep - 1, vec[u].l);
if (vec[u].r >= 0) query_(ax, (ay + by) >> 1, bx, by, dep - 1, vec[u].r);
}
}
vector<int> query(long long LX, long long LY, long long RX, long long RY) {
LX = max(LX, 0LL); LY = max(LY, 0LL); RX = min(RX, (1LL << 31)); RY = min(RY, (1LL << 31));
lx = LX; ly = LY; rx = RX; ry = RY;
V.clear();
query_(0, 0, (1LL << 31), (1LL << 31), 62, 0);
return V;
}
};
long long N, X[1 << 18], Y[1 << 18], R[1 << 18], score[1 << 18];
bool used[1 << 18];
long long dist(int p1, int p2) {
return (X[p1] - X[p2]) * (X[p1] - X[p2]) + abs(Y[p1] - Y[p2]) * abs(Y[p1] - Y[p2]);
}
void solve_Jury() {
while (true) {
int maxn = -1, id = -1;
for (int i = 1; i <= N; i++) {
if (used[i] == true) continue;
if (maxn < R[i]) { maxn = R[i]; id = i; }
}
if (id == -1) break;
for (int i = 1; i <= N; i++) {
if (used[i] == true) continue;
if (dist(id, i) <= (R[i] + R[id]) * (R[i] + R[id])) { used[i] = true; score[i] = id; }
}
}
}
bool uses[1 << 19]; SegmentTree Z;
void solve_subtasks() {
priority_queue<pair<long long, int>, vector<pair<long long, int>>, less<pair<long long, int>>>Q;
Z.init();
for (int i = 1; i <= N; i++) Q.push(make_pair(R[i], -i));
for (int i = 1; i <= N; i++) Z.add(X[i], Y[i], i);
while (!Q.empty()) {
int pos = -Q.top().second;
vector<int>E = Z.query(X[pos] - 2LL * R[pos], Y[pos] - 2LL * R[pos], X[pos] + 2LL * R[pos] + 1LL, Y[pos] + 2LL * R[pos] + 1LL);
for (int i = 0; i < E.size(); i++) {
if (dist(pos, E[i]) <= 1LL * (R[pos] + R[E[i]]) * (R[pos] + R[E[i]])) {
Z.lose(X[E[i]], Y[E[i]], E[i]);
used[E[i]] = true;
score[E[i]] = pos;
}
}
while (!Q.empty()) { int pos = -Q.top().second; if (used[pos] == false) break; Q.pop(); }
}
}
int main() {
scanf("%lld", &N);
for (int i = 1; i <= N; i++) { scanf("%lld%lld%lld", &X[i], &Y[i], &R[i]); X[i] += (1LL << 30); Y[i] += (1LL << 30); }
if (N <= 5000) {
solve_Jury();
}
else {
solve_subtasks();
}
for (int i = 1; i <= N; i++) {
if (i >= 2) printf(" ");
printf("%lld", score[i]);
}
printf("\n");
return 0;
}
Compilation message
circle_selection.cpp:5:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning (disable: 4996)
circle_selection.cpp: In function 'void solve_subtasks()':
circle_selection.cpp:138:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < E.size(); i++) {
~~^~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:150:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &N);
~~~~~^~~~~~~~~~~~
circle_selection.cpp:151:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i = 1; i <= N; i++) { scanf("%lld%lld%lld", &X[i], &Y[i], &R[i]); X[i] += (1LL << 30); Y[i] += (1LL << 30); }
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 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 |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
356 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
356 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
408 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
7 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
194 ms |
568 KB |
Output is correct |
23 |
Correct |
169 ms |
576 KB |
Output is correct |
24 |
Correct |
194 ms |
568 KB |
Output is correct |
25 |
Correct |
161 ms |
568 KB |
Output is correct |
26 |
Correct |
182 ms |
564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
120 ms |
12844 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2249 ms |
135764 KB |
Output is correct |
3 |
Runtime error |
169 ms |
20024 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
167 ms |
6456 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 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 |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
356 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
356 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
408 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
7 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
194 ms |
568 KB |
Output is correct |
23 |
Correct |
169 ms |
576 KB |
Output is correct |
24 |
Correct |
194 ms |
568 KB |
Output is correct |
25 |
Correct |
161 ms |
568 KB |
Output is correct |
26 |
Correct |
182 ms |
564 KB |
Output is correct |
27 |
Correct |
51 ms |
9072 KB |
Output is correct |
28 |
Correct |
53 ms |
9036 KB |
Output is correct |
29 |
Correct |
53 ms |
9068 KB |
Output is correct |
30 |
Correct |
95 ms |
9064 KB |
Output is correct |
31 |
Correct |
66 ms |
9128 KB |
Output is correct |
32 |
Correct |
61 ms |
9068 KB |
Output is correct |
33 |
Correct |
653 ms |
135872 KB |
Output is correct |
34 |
Correct |
628 ms |
135724 KB |
Output is correct |
35 |
Correct |
684 ms |
135752 KB |
Output is correct |
36 |
Correct |
899 ms |
135760 KB |
Output is correct |
37 |
Correct |
896 ms |
138344 KB |
Output is correct |
38 |
Correct |
1140 ms |
138436 KB |
Output is correct |
39 |
Execution timed out |
3097 ms |
13664 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 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 |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
356 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
356 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
408 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
7 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
194 ms |
568 KB |
Output is correct |
23 |
Correct |
169 ms |
576 KB |
Output is correct |
24 |
Correct |
194 ms |
568 KB |
Output is correct |
25 |
Correct |
161 ms |
568 KB |
Output is correct |
26 |
Correct |
182 ms |
564 KB |
Output is correct |
27 |
Runtime error |
120 ms |
12844 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
28 |
Halted |
0 ms |
0 KB |
- |