This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
void kout(){ cerr << endl; }
template<class T1, class ...T2> void kout(T1 a, T2 ...e) { cerr << a << ' ', kout(e...); }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010, MAX_K = 32;
int n;
ll up(ll v) { return v * v; }
int die[MAX_N];
struct cir {
ll x, y, r, id;
pair<int,int> div(int d) {
return {x/d, y/d};
}
friend bool inter(cir a, cir b) {
return up(a.x-b.x) + up(a.y-b.y) <= up(a.r+b.r);
}
bool operator < (cir a) {
return make_pair(-r, id) < make_pair(-a.r, a.id);
}
bool set(cir killer) {
if (die[id] != -1)
return true;
if (inter(killer, *(this)))
return die[id] = killer.id, true;
return false;
}
bool dead() { return die[id] != -1; }
friend istream& operator >> (istream& in, cir &a) {
static int cnt;
//const static ll dx = 12398291, dy = -23412845234;
const static ll dx = 0, dy = 0;
return a.id = cnt++, in >> a.x >> a.y >> a.r, a.x += dx, a.y += dy, in;
}
}a[MAX_N];
void brute_force() {
for (int i = 0;i < n;++i) {
int id = a[i].id;
if (~die[id]) continue;
die[id] = id;
for (int j = i+1;j < n;++j)
a[j].set(a[i]);
}
}
//random_device rd;
//mt19937 gen(rd());
//uniform_int_
//struct hs {
// size_t operator()(pair<int,int> a) const {
// const static unsigned long long f = 9823419848328479ll;
// return f * a.first - a.second + (a.first ^ a.second);
// }
//};
//
//unordered_map<pair<int,int>, vector<int>, hs> mp[MAX_K];
struct allcir {
vector<pair<int,vector<pair<int,int>>>> mp;
ll block_size = 1ll << 31;
void shrink(ll sz) {
if (sz < block_size)
block_size = sz, putall();
}
void putall() {
mp.clear();
vector<pair< pair<int,int> , int > > allp;
for (int i = 0;i < n;++i) if (!a[i].dead())
allp.pb( a[i].div(block_size), i );
sort(AI(allp));
for (auto [P, id] : allp) {
if (mp.empty() || P.first != mp.back().first)
mp.pb(P.first, 0);
mp.back().second.pb(P.second, id);
}
for (auto &[x, v] : mp)
sort(AI(v));
}
void killall(cir a) {
auto [x, y] = a.div(block_size);
auto it = lower_bound(AI(mp), pair<int,vector<pair<int,int>>>{x-2, vector<pair<int,int>>{}});
while (it != end(mp) && x + 2 >= it->first) {
auto &vec = it->second;
auto vit = lower_bound(AI(vec), pair<int,int>{ y - 2, -1});
while (vit != end(vec) && y + 2 >= vit->first)
::a[vit->second].set(a), ++vit;
++it;
}
}
}grid;
void solve_all() {
// for (int i = 0;i < n;++i) {
// for (int j = 0;j < MAX_K;++j)
// mp[j][ a[i].div(1ll<<j) ].pb(i);
// }
grid.putall();
for (int i = 0;i < n;++i) {
if (a[i].dead())
continue;
a[i].set(a[i]);
int j = 0;
while ((1ll<<j) < a[i].r)
++j;
grid.shrink(1ll << j);
grid.killall(a[i]);
// for (int r : {j}) {
// grid.killall(a[i]);
// auto &mp = ::mp[r];
// auto [x, y] = a[i].div(1ll << r);
// for (int nx : {x-2, x-1, x, x+1, x+2})
// for (int ny : {y-2, y-1, y, y+1, y+2})
// if (mp.count({nx, ny})) {
// auto &V = mp[{nx, ny}];
// vector<int> nv;
// for (int j : V)
// if (!a[j].set(a[i]))
// nv.pb(j);
// swap(nv, V);
// }
// break;
// }
}
}
//void testmap() {
// mp.reserve(n * 10);
// int rad = a[0].r ;
// for (int i = 1;i < n;++i)
// if (rad != a[i].r) exit(1);
//
// rad <<= 1;
//
// for (int i = 0;i < n;++i)
// mp[ a[i].div(rad) ].pb(i);
//
// for (int i = 0;i < n;++i) {
// if (a[i].dead()) continue;
// a[i].set(a[i]);
// auto [x, y] = a[i].div(rad);
//
// for (int nx : {x-1, x, x+1})
// for (int ny : {y-1, y, y+1})
// if (mp.count({nx, ny})) {
// auto &V = mp[{nx, ny}];
// vector<int> nv;
// for (int j : V)
// if (!a[j].set(a[i]))
// nv.pb(j);
// swap(nv, V);
// }
// }
//}
void solve() {
sort(a, a+n);
fill(die, die+n, -1);
solve_all();
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 0;i < n;++i)
cin >> a[i];
solve();
for (int i = 0;i < n;++i)
cout << die[i]+1 << " \n"[i+1==n];
}
# | 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... |