Submission #254320

#TimeUsernameProblemLanguageResultExecution timeMemory
254320shayan_pCircle selection (APIO18_circle_selection)C++14
60 / 100
3096 ms43784 KiB
// And you curse yourself for things you never done
 
#include<bits/stdc++.h>
 
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

const int maxn = 3e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
 
pair<pll, ll> p[maxn];
int arr[maxn], ans[maxn];
 
pll operator - (pll a, pll b){
    return {a.F - b.F, a.S - b.S};
}
pll operator + (pll a, pll b){
    return {a.F + b.F, a.S + b.S};
}
ll operator ^ (pll a, pll b){
    return 1ll * a.F * b.F + 1ll * a.S * b.S;
}
bool ok(int i, int j){
    return 1ll * (p[j].S + p[i].S) * (p[j].S + p[i].S) >= ((p[i].F - p[j].F) ^ (p[i].F - p[j].F));
}

struct Hash{
    int operator() (const pii &p)const{
	return hash<ll>()( (ll(p.F) << 32) | ll(p.S) );
    }
};

unordered_map<pii, vector<int>, Hash> mp;
int Log = 31;
int n;

int cnt[maxn];

void reSize(){
    mp.clear();
    for(int i = 0; i < n; i++){
	if(ans[i] == -1)
	    mp[{p[i].F.F >> Log, p[i].F.S >> Log}].PB(i);
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    memset(ans, -1, sizeof ans);
    
    cin >> n;

    for(int i = 0; i < n; i++){
	cin >> p[i].F.F >> p[i].F.S >> p[i].S;
	p[i].F.F+= inf, p[i].F.S+= inf;
    }
    auto cmp = [](int i, int j){
		   return (p[i].S == p[j].S ? i > j : p[i].S < p[j].S);
	       };
    iota(arr, arr + n, 0);
    sort(arr, arr + n, cmp);
    
    for(int I = n-1; I >= 0; I--){
	int i = arr[I];
	bool done = 0;
	while(Log > 0 && (1<<(Log-1)) >= p[i].S)
	    Log--, done = 1;
	if(done)
	    reSize();
	if(ans[i] == -1){
	    ans[i] = i;
	    int x = p[i].F.F >> Log, y = p[i].F.S >> Log;
	    for(int X = x-2; X <= x+2; X++){
		for(int Y = y-2; Y <= y+2; Y++){
		    if(mp.count({X, Y})){
			vector<int> vec;
			for(int id : mp[{X, Y}]){
			    if(ans[id] == -1 && ok(id, i))
				ans[id] = i;
			    if(ans[id] == -1)
				vec.PB(id);//, assert(++cnt[id] <= 10);
			}
			if(!vec.empty())
			    mp[{X, Y}] = vec;
		    }
		}
	    }
	}
    }
    for(int i = 0; i < n; i++){
	cout << ans[i] + 1 << " ";
    }
    return cout << endl, 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...