This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#define _GLIBCXX_DEBUG
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//
//using namespace __gnu_pbds;
//
//template<typename T>
//using ordered_set = tree<T, null_type, less < T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define trace(x) cout << #x << ": " << (x) << endl;
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define uniq(x) x.resize(unique(all(x)) - begin(x))
#define sz(s) ((int) size(s))
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define int128 __int128
#define pb push_back
#define popb pop_back
#define eb emplace_back
#define fi first
#define se second
#define itn int
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
template<typename T>
bool ckmn(T &x, T y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template<typename T>
bool ckmx(T &x, T y) {
if (x < y) {
x = y;
return true;
}
return false;
}
int bit(int x, int b) {
return (x >> b) & 1;
}
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
const ll infL = 3e18;
const int infI = 1000000000 + 7;
const int infM = 0x3f3f3f3f; //a little bigger than 1e9
const ll infML = 0x3f3f3f3f3f3f3f3fLL; //4.5e18
const int N = 300002;
const int mod = 998244353;
const ld eps = 1e-9;
int x[N], y[N], r[N], ans[N];
auto inter = [](int i, int j) {
return ((ll) x[i] - x[j]) * (x[i] - x[j]) + ((ll) y[i] - y[j]) * (y[i] - y[j]) <=
(r[i] + r[j]) * ((ll) r[i] + r[j]);
};
int R;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i] >> r[i];
}
memset(ans, -1, sizeof(ans));
vector<int> ordd(n);
iota(all(ordd), 0);
sort(all(ordd), [](int i, int j) {
if (r[i] != r[j]) return r[i] > r[j];
return i < j;
});
R = infI * 2;
vector<vector<pair<int, int>>> points;
vector<int> ordx(n), ordy(n), scl_x, pos(n);
iota(all(ordx), 0);
iota(all(ordy), 0);
sort(all(ordx), [](int i, int j) {
return x[i] < x[j];
});
sort(all(ordy), [](int i, int j) {
return y[i] < y[j];
});
auto rescale = [&](int rr) {
R = rr;
scl_x.clear();
for (int i = 0; i < n; ++i) {
int nw = x[ordx[i]] / R;
if (scl_x.empty() || scl_x.back() != nw) {
scl_x.push_back(nw);
}
pos[ordx[i]] = sz(scl_x) - 1;
}
points.clear();
points.resize(sz(scl_x));
for (int i = 0; i < sz(points); ++i) assert(points[i].empty());
for (int i: ordy) {
points[pos[i]].eb(y[i] / R, i);
}
};
for (int i: ordd) {
if (R >= r[i] * 2) {
rescale(r[i]);
}
if (ans[i] == -1) {
int lx = lower_bound(all(scl_x), x[i] / R - 2) - begin(scl_x), rx =
upper_bound(all(scl_x), x[i] / R + 2) - begin(scl_x);
for (int f = lx; f < rx; ++f) {
int ly = lower_bound(all(points[f]), mp(y[i] / R - 2, -1)) - begin(points[f]), ry =
upper_bound(all(points[f]), mp(y[i] / R + 3, -1)) - begin(points[f]);
for (int j = ly; j < ry; ++j) {
if (ans[points[f][j].second] == -1 && inter(i, points[f][j].second)) {
ans[points[f][j].second] = i;
}
}
}
}
}
for (int i = 0; i < n; ++i) {
cout << ans[i] + 1 << " ";
}
return 0;
}
# | 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... |