Submission #514937

# Submission time Handle Problem Language Result Execution time Memory
514937 2022-01-18T20:56:03 Z AugustinasJucas Circle selection (APIO18_circle_selection) C++14
37 / 100
3000 ms 899228 KB
#include <bits/stdc++.h>
using namespace std;
const long long inf = 2.1e9 + 1;
const long long dydis = (3e5+1);
const int dd = 21;
int n, m, v, ind;
long long x, y, kur, R;
int dbInd = 0;
int mInd[dd] = {};
vector<int> allX;
vector<int> l, r, ml, mr;
vector<long long> treeVals[dd];
vector<vector<long long> > base;
vector<pair<pair<int, int>, pair<int, long long> > > mas;
bitset<dydis> circleRemoved;
bitset<(4 * dydis)> removed[dd];
vector<pair<int, int> > kurYra[dydis];
vector<int> rightmost[dd];
vector<int> sz[dd];
vector<int> tevas[dd];
int by[dydis];
vector<int> unique(vector<int> &a) {
	vector<int> ret;
	sort(a.begin(), a.end());
	for(auto &x : a){
		if(ret.size() == 0 || ret.back() != x) ret.push_back(x); 
	}
	return ret;
}
int m1, m2;
int h[dydis * 4];
void build(int v, int he = 0) {
	h[v] = he;
	if(v >= m){
		l[v] = r[v] = dbInd++;
		ml[v] = mInd[he];
		for(auto &x : base[l[v]]) {
			treeVals[he][mInd[he]++] = x;
		}
		mr[v] = mInd[he]-1;
	}else {
		build(v*2, he+1);
		build(v*2+1, he+1);
		
		l[v] = l[v*2];
		r[v] = r[v*2+1];
		ml[v] = mInd[he];
		
		m1 = ml[v*2];
		m2 = ml[v*2+1];
		while(true) {
			if(m1 == mr[v*2]+1 && m2 == mr[v*2+1]+1) break;
			if(m1 == mr[v*2]+1) {
				treeVals[he][mInd[he]++] = treeVals[he+1][m2++];
			}else if(m2 == mr[v*2+1]+1){
				treeVals[he][mInd[he]++] = treeVals[he+1][m1++];
			}else if(treeVals[he+1][m1] <= treeVals[he+1][m2]){
				treeVals[he][mInd[he]++] = treeVals[he+1][m1++];
			}else {
				treeVals[he][mInd[he]++] = treeVals[he+1][m2++];
			}
		}
		mr[v] = mInd[he]-1;
	}
	for(int i = ml[v]; i <= mr[v]; i++) {
		kurYra[treeVals[he][i]%dydis].push_back({v, i});
	}
}
int vec[dydis]; 
int id = 0, ret;
int fP(int v, int he) {
	id = 0;
	while(true) {
		vec[id++] = v;
		ret = v;
		if(tevas[he][v] == v) break;
		v = tevas[he][v];
	}
	for(int i = 0; i < id; i++) tevas[he][vec[i]] = ret;
	return ret;
}
void conn(int a, int b, int he) {
	a = fP(a, he);
	b = fP(b, he);
	if(sz[he][a] < sz[he][b]) swap(a, b); 
	tevas[he][b] = a;
	sz[he][a] += sz[he][b];
	rightmost[he][a] = max(rightmost[he][a], rightmost[he][b]);
}
void remove(int ind){
	if(circleRemoved[ind]) return ;
	circleRemoved[ind] = 1;
	int i;
	for(auto &x : kurYra[ind]) {
		v = x.first;
		i = x.second;
		removed[h[v]][i] = 1;
		if(i-1 >= ml[v] && removed[h[v]][i-1]) {
			conn(i-1, i, h[v]);
		}
		if(i+1 <= mr[v] && removed[h[v]][i+1]) {
			conn(i+1, i, h[v]);
		}
	}
}
/*
void print(int v) {
	if(v < m){
		print(v*2);
		print(v*2+1);
	}
	cout << "v = " << v << ", [" << l[v] << "; " << r[v] << "], atitinkamas masyvas: ["; 
	for(int i = ml[v]; i <= mr[v]; i++) {
		if(removed[i]) continue;
		cout << "(y=" << treeVals[i]/dydis << ", i=" << treeVals[i]%dydis << ")";
		if(i != mr[v]) cout << ", ";
	}
	cout << "]\n";
}*/
long long X1, Y1, R1, X2, Y2, R2;
bool kertasi (int i, int j) {
	X1 = mas[i].second.first; Y1 = mas[i].second.second; R1 = mas[i].first.first;
	X2 = mas[j].second.first; Y2 = mas[j].second.second; R2 = mas[j].first.first;
	return (X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2) <= (R1 + R2) * (R1 + R2);
}
int beg;
bitset<dydis> selected;
int selList[dydis];
int selInd = 0;
void find(int v, int L, int R, long long down, long long up){
	if(L <= l[v] && r[v] <= R) {
		beg = lower_bound(treeVals[h[v]].begin() + ml[v], treeVals[h[v]].begin() + mr[v] + 1, 1ll * down * dydis) - treeVals[h[v]].begin();
		for(int i = beg; i <= mr[v]; i++) {
			if(treeVals[h[v]][i] / dydis > up) break;
			if(removed[h[v]][i]) {
				i = rightmost[h[v]][fP(i, h[v])];
				continue;
			}
			if(!selected[treeVals[h[v]][i]%dydis]) {
				selected[treeVals[h[v]][i]%dydis] = 1;
				selList[selInd++] = treeVals[h[v]][i]%dydis;
			}
		}
		
	}else if(r[v] < L || R < l[v]) {
		
	}else{
		find(v*2, L, R, down, up);
		find(v*2+1, L, R, down, up);
	}
}
int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	l.resize(4 * dydis);
	r.resize(4 * dydis);
	ml.resize(4 * dydis);
	mr.resize(4 * dydis);
	for(int i = 0; i < dd; i++){
		rightmost[i].resize(4*dydis);
		treeVals[i].resize(4*dydis);
		sz[i].resize(4*dydis);
		tevas[i].resize(4*dydis);
	}
	for(int j = 0; j < dd; j++){
		for(int i = 0; i < (int) tevas[j].size(); i++) {
			tevas[j][i] = i;
			sz[j][i] = 1;
			rightmost[j][i] = i;
		}
	}
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> x >> y >> R;
		y += inf;
		mas.push_back({{R, -i}, {x, y}});
	}
		
	sort(mas.begin(), mas.end());
	reverse(mas.begin(), mas.end());
	for(auto &x : mas) x.first.second *= -1;
	
	for(int i = 0; i < n; i++) {
		allX.push_back(mas[i].second.first-mas[i].first.first);
		allX.push_back(mas[i].second.first+mas[i].first.first);
	}
	allX = unique(allX);
	base.resize(allX.size());
	m = allX.size();
	
	for(int i = 0; i < n; i++) {
		x = mas[i].second.first;
		y = mas[i].second.second;
		R = mas[i].first.first;
		
		kur = lower_bound(allX.begin(), allX.end(), x+R) - allX.begin();
		base[kur].push_back(1ll*(y-R)*dydis + i);
		base[kur].push_back(1ll*(y+R)*dydis + i);
		
		kur = lower_bound(allX.begin(), allX.end(), x-R) - allX.begin();
		base[kur].push_back(1ll*(y-R)*dydis + i);
		base[kur].push_back(1ll*(y+R)*dydis + i);
	}
	
	for(auto &x : base) sort(x.begin(), x.end());
	
	build(1);
	long long L, R, ll, rr;
	for(int i = 0; i < n; i++) {
		if(circleRemoved[i]) continue;
		L = mas[i].second.first - mas[i].first.first;
		R = mas[i].second.first + mas[i].first.first;
		ll = lower_bound(allX.begin(), allX.end(), L) - allX.begin();
		rr = lower_bound(allX.begin(), allX.end(), R) - allX.begin();
		selInd = 0;
		find(1, ll, rr, mas[i].second.second - mas[i].first.first, mas[i].second.second + mas[i].first.first);
		for(int j = 0; j < selInd; j++){
			selected[selList[j]] = 0;
			if(!kertasi(i, selList[j])) continue;
			remove(selList[j]);
			by[mas[selList[j]].first.second] = mas[i].first.second;
		}
	}
	for(int i = 0; i < n; i++) {
		cout << by[i] + 1 << " ";
	}
	return 0;
}
/*
5
0 0 3
5 -2 2
5 0 1
1 1 1
1 -3 1

 11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1 
 
 

*/
# Verdict Execution time Memory Grader output
1 Correct 232 ms 519376 KB Output is correct
2 Correct 252 ms 519376 KB Output is correct
3 Correct 231 ms 519296 KB Output is correct
4 Correct 245 ms 519364 KB Output is correct
5 Correct 226 ms 519296 KB Output is correct
6 Correct 233 ms 519476 KB Output is correct
7 Correct 268 ms 519412 KB Output is correct
8 Correct 224 ms 519472 KB Output is correct
9 Correct 228 ms 519484 KB Output is correct
10 Correct 231 ms 519496 KB Output is correct
11 Correct 227 ms 519364 KB Output is correct
12 Correct 236 ms 519364 KB Output is correct
13 Correct 241 ms 519516 KB Output is correct
14 Correct 231 ms 519408 KB Output is correct
15 Correct 223 ms 519492 KB Output is correct
16 Correct 244 ms 520164 KB Output is correct
17 Correct 237 ms 520136 KB Output is correct
18 Correct 229 ms 520180 KB Output is correct
19 Correct 262 ms 523312 KB Output is correct
20 Correct 265 ms 523312 KB Output is correct
21 Correct 249 ms 523280 KB Output is correct
22 Correct 258 ms 523004 KB Output is correct
23 Correct 267 ms 523080 KB Output is correct
24 Correct 255 ms 523080 KB Output is correct
25 Correct 280 ms 522984 KB Output is correct
26 Correct 247 ms 522976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3084 ms 899228 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 247 ms 519420 KB Output is correct
2 Correct 1448 ms 642832 KB Output is correct
3 Execution timed out 3054 ms 885064 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3123 ms 885644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 232 ms 519376 KB Output is correct
2 Correct 252 ms 519376 KB Output is correct
3 Correct 231 ms 519296 KB Output is correct
4 Correct 245 ms 519364 KB Output is correct
5 Correct 226 ms 519296 KB Output is correct
6 Correct 233 ms 519476 KB Output is correct
7 Correct 268 ms 519412 KB Output is correct
8 Correct 224 ms 519472 KB Output is correct
9 Correct 228 ms 519484 KB Output is correct
10 Correct 231 ms 519496 KB Output is correct
11 Correct 227 ms 519364 KB Output is correct
12 Correct 236 ms 519364 KB Output is correct
13 Correct 241 ms 519516 KB Output is correct
14 Correct 231 ms 519408 KB Output is correct
15 Correct 223 ms 519492 KB Output is correct
16 Correct 244 ms 520164 KB Output is correct
17 Correct 237 ms 520136 KB Output is correct
18 Correct 229 ms 520180 KB Output is correct
19 Correct 262 ms 523312 KB Output is correct
20 Correct 265 ms 523312 KB Output is correct
21 Correct 249 ms 523280 KB Output is correct
22 Correct 258 ms 523004 KB Output is correct
23 Correct 267 ms 523080 KB Output is correct
24 Correct 255 ms 523080 KB Output is correct
25 Correct 280 ms 522984 KB Output is correct
26 Correct 247 ms 522976 KB Output is correct
27 Correct 295 ms 527144 KB Output is correct
28 Correct 303 ms 527012 KB Output is correct
29 Correct 291 ms 527064 KB Output is correct
30 Correct 311 ms 526592 KB Output is correct
31 Correct 315 ms 526628 KB Output is correct
32 Correct 300 ms 526556 KB Output is correct
33 Correct 1397 ms 649048 KB Output is correct
34 Correct 1376 ms 648716 KB Output is correct
35 Correct 1450 ms 647760 KB Output is correct
36 Correct 1382 ms 642452 KB Output is correct
37 Correct 1376 ms 642612 KB Output is correct
38 Correct 1563 ms 642616 KB Output is correct
39 Correct 1026 ms 581700 KB Output is correct
40 Correct 891 ms 581684 KB Output is correct
41 Correct 905 ms 581668 KB Output is correct
42 Correct 909 ms 581748 KB Output is correct
43 Correct 1249 ms 642244 KB Output is correct
44 Correct 1223 ms 642176 KB Output is correct
45 Correct 1213 ms 642312 KB Output is correct
46 Correct 1196 ms 642244 KB Output is correct
47 Correct 1250 ms 642204 KB Output is correct
48 Correct 1239 ms 642340 KB Output is correct
49 Correct 1288 ms 642164 KB Output is correct
50 Correct 1221 ms 642228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 232 ms 519376 KB Output is correct
2 Correct 252 ms 519376 KB Output is correct
3 Correct 231 ms 519296 KB Output is correct
4 Correct 245 ms 519364 KB Output is correct
5 Correct 226 ms 519296 KB Output is correct
6 Correct 233 ms 519476 KB Output is correct
7 Correct 268 ms 519412 KB Output is correct
8 Correct 224 ms 519472 KB Output is correct
9 Correct 228 ms 519484 KB Output is correct
10 Correct 231 ms 519496 KB Output is correct
11 Correct 227 ms 519364 KB Output is correct
12 Correct 236 ms 519364 KB Output is correct
13 Correct 241 ms 519516 KB Output is correct
14 Correct 231 ms 519408 KB Output is correct
15 Correct 223 ms 519492 KB Output is correct
16 Correct 244 ms 520164 KB Output is correct
17 Correct 237 ms 520136 KB Output is correct
18 Correct 229 ms 520180 KB Output is correct
19 Correct 262 ms 523312 KB Output is correct
20 Correct 265 ms 523312 KB Output is correct
21 Correct 249 ms 523280 KB Output is correct
22 Correct 258 ms 523004 KB Output is correct
23 Correct 267 ms 523080 KB Output is correct
24 Correct 255 ms 523080 KB Output is correct
25 Correct 280 ms 522984 KB Output is correct
26 Correct 247 ms 522976 KB Output is correct
27 Execution timed out 3084 ms 899228 KB Time limit exceeded
28 Halted 0 ms 0 KB -