This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* There's someone in my head but it's not me */
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define all(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define F first
#define S second
#define lc id << 1
#define rc lc | 1
const int N = 3e5 + 4, MOD = 1e9 + 7;
int n, X[N], Y[N], R[N], ord[N], ret[N], id[N]; ll base[N];
set<pii> seg[N << 2];
vector <ll> cm;
bool cmp(int i, int j) {
return R[i] > R[j];
}
int intersect(int i, int j) {
return (base[i] + base[j] + 2ll * (1ll * X[i] * X[j] + 1ll * Y[i] * Y[j] + 1ll * R[i] * R[j])) >= 0;
}
int lwr(ll x) {
return lower_bound(all(cm), x) - cm.begin() + 1;
}
void add(int pos, pii x) {
pos += SZ(cm);
while (pos) {
seg[pos].insert(x);
pos >>= 1;
}
}
void get(int ql, int qr, ll yl, ll yr, int p) {
ql += SZ(cm), qr += SZ(cm);
while (qr - ql > 0) {
if (ql & 1) {
for (auto it = seg[ql].lower_bound({yl, -1e9}); it != seg[ql].end() && it->F <= yr; ) {
auto x = *it;
if (ret[x.S]) seg[ql].erase(x);
else if (intersect(p, x.S)) ret[x.S] = p;
it = seg[ql].upper_bound(x);
}
ql++;
}
if (qr & 1) {
qr--;
for (auto it = seg[qr].lower_bound({yl, -1e9}); it != seg[qr].end() && it->F <= yr; ) {
auto x = *it;
if (ret[x.S]) seg[qr].erase(x);
else if (intersect(p, x.S)) ret[x.S] = p;
it = seg[qr].upper_bound(x);
}
}
qr >>= 1, ql >>= 1;
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d%d", &X[i], &Y[i], &R[i]), base[i] = 1ll * R[i] * R[i] - 1ll * X[i] * X[i] - 1ll * Y[i] * Y[i], cm.push_back(X[i]), ord[i] = i;
sort(ord + 1, ord + n + 1, cmp);
sort(all(cm));
cm.resize(unique(all(cm)) - cm.begin());
for(int i = 1; i <= n; i ++) {
int I = ord[i];
add(lwr(X[I]), make_pair(Y[I], I));
}
for (int _ = 1; _ <= n; _++) {
int i = ord[_];
if (ret[i]) continue;
get(lwr(X[i] - 2ll * R[i]), lwr(X[i] + 2ll * R[i] + 1), Y[i] - 2ll * R[i], Y[i] + 2ll * R[i], i);
}
for (int i = 1; i <= n; i++) printf("%d ", ret[i]);
printf("\n");
return 0;
}
Compilation message (stderr)
circle_selection.cpp:3: warning: ignoring #pragma comment [-Wunknown-pragmas]
3 | #pragma comment(linker, "/stack:200000000")
|
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
72 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
74 | scanf("%d%d%d", &X[i], &Y[i], &R[i]), base[i] = 1ll * R[i] * R[i] - 1ll * X[i] * X[i] - 1ll * Y[i] * Y[i], cm.push_back(X[i]), ord[i] = i;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |