#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define MAX_N (long long)(2e9+10)
int N;
int X[300000], Y[300000], R[300000];
bool used[300000];
int U[300000];
vector<int> eraselist;
struct SegTree2{
SegTree2 *left = NULL, *right = NULL;
set<int> seg;
void add(int a, int b, int id, long long l=0, long long r=MAX_N) {
if (b <= l || r <= a) return;
if (seg.find(id) == seg.end()) seg.insert(id);
else seg.erase(id);
if (a <= l && r <= b) return;
if (left == NULL) left = new SegTree2();
if (right == NULL) right = new SegTree2();
left->add(a, b, id, l, (0LL+l+r)/2);
right->add(a, b, id, (0LL+l+r)/2, r);
}
void list(int a, int b, int par, long long l=0, long long r=MAX_N) {
if (b <= l || r <= a) return;
for (int t : seg) if (!used[t]) {
if (1LL*(X[par]-X[t])*(X[par]-X[t]) + 1LL*(Y[par]-Y[t])*(Y[par]-Y[t]) <= 1LL*(R[par]+R[t])*(R[par]+R[t])) {
//cout<<par<<"->"<<t<<"\n";
U[t] = par;
used[t] = true;
eraselist.pb(t);
}
//else cout<<"par="<<par<<"->t="<<t<<" ? no\n";
}
if (a <= l && r <= b) return;
int mid = (0LL+l+r)/2;
if (left) left->list(a, b, par, l, mid);
if (right) right->list(a, b, par, mid, r);
}
};
struct SegTree{
SegTree *left = NULL, *right = NULL;
SegTree2 *seg = new SegTree2();
void add(int a, int b, P p, int id, long long l=0, long long r=MAX_N) {
if (b <= l || r <= a) return;
//cout<<"["<<l-1e9<<","<<r-1e9<<") <- "<<id<<"\n";
seg->add(p._1, p._2, id);
if (a <= l && r <= b) return;
if (left == NULL) left = new SegTree();
if (right == NULL) right = new SegTree();
left->add(a, b, p, id, l, (0LL+l+r)/2);
right->add(a, b, p, id, (0LL+l+r)/2, r);
}
void list(int a, int b, int ya, int yb, int par, long long l=0, long long r=MAX_N) {
if (b <= l || r <= a) return;
seg->list(ya, yb, par);
if (a <= l && r <= b) return;
int mid = (0LL+l+r)/2;
if (left) left->list(a, b, ya, yb, par, l, mid);
if (right) right->list(a, b, ya, yb, par, mid, r);
}
};
SegTree *seg = new SegTree();
vector<pair<P, P> > create(int x, int y, int r) {
vector<pair<P, P> > ret;
ret.pb(make_pair(P(x-r, x+r), P(y-r, y+r)));
return ret;
}
void add_item(int i) {
for (auto p : create(X[i], Y[i], R[i])) seg->add(max(0, p._1._1), min(p._1._2+1, (int)MAX_N), P(max(p._2._1, 0), min(p._2._2+1, (int)MAX_N)), i);
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N;
rep(i, N) cin >> X[i] >> Y[i] >> R[i], X[i] += 1e9, Y[i] += 1e9;
vector<P> vs;
rep(i, N) vs.pb(P(-R[i], i));
sort(all(vs));
rep(i, N) add_item(i);
rep(i, N) U[i] = -1;
for (P p : vs) if (!used[p._2]) {
int i = p._2;
//cout<<"par="<<i<<"\n";
used[i] = true;
U[i] = i;
add_item(i);
for (auto p : create(X[i], Y[i], R[i])) seg->list(max(0, p._1._1), min(p._1._2+1, (int)MAX_N), max(p._2._1, 0), min(p._2._2+1, (int)MAX_N), i);
//seg->list(X[i], Y[i], i);
for (int t : eraselist) add_item(t);
eraselist.clear();
}
rep(i, N) cout << U[i]+1 << " ";cout<<"\n";
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:17:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
#define rep(i, n) for (int i=0; i<(n); i++)
^
circle_selection.cpp:122:3: note: in expansion of macro 'rep'
rep(i, N) cout << U[i]+1 << " ";cout<<"\n";
^~~
circle_selection.cpp:122:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
rep(i, N) cout << U[i]+1 << " ";cout<<"\n";
^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
760 KB |
Output is correct |
2 |
Correct |
6 ms |
2536 KB |
Output is correct |
3 |
Correct |
9 ms |
3988 KB |
Output is correct |
4 |
Correct |
9 ms |
3988 KB |
Output is correct |
5 |
Correct |
12 ms |
6340 KB |
Output is correct |
6 |
Incorrect |
45 ms |
24244 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3079 ms |
982988 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
982988 KB |
Output is correct |
2 |
Runtime error |
2086 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2191 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
760 KB |
Output is correct |
2 |
Correct |
6 ms |
2536 KB |
Output is correct |
3 |
Correct |
9 ms |
3988 KB |
Output is correct |
4 |
Correct |
9 ms |
3988 KB |
Output is correct |
5 |
Correct |
12 ms |
6340 KB |
Output is correct |
6 |
Incorrect |
45 ms |
24244 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
760 KB |
Output is correct |
2 |
Correct |
6 ms |
2536 KB |
Output is correct |
3 |
Correct |
9 ms |
3988 KB |
Output is correct |
4 |
Correct |
9 ms |
3988 KB |
Output is correct |
5 |
Correct |
12 ms |
6340 KB |
Output is correct |
6 |
Incorrect |
45 ms |
24244 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |