답안 #835532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
835532 2023-08-23T15:32:04 Z jamielim 원 고르기 (APIO18_circle_selection) C++14
0 / 100
2064 ms 39608 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
typedef vector<int> vi;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;

int n;
i4 arr[300005];
int ans[300005];
set<i4> pq;
int scale=(1<<30);
map<int,vector<ii> > m;

inline void downscale(){
	scale/=2;
	m.clear();
	for(i4 i:pq){
		m[i.se.fi/scale].pb(i.se.se/scale,-i.fi.se);
	}
	for(auto it=m.begin();it!=m.end();++it){
		sort(ALL(it->se));
	}
}

inline bool intersect(int a,int b){
	printf("%d %d\n",a,b);
	ll dx=arr[a].se.fi-arr[b].se.fi;
	ll dy=arr[a].se.se-arr[b].se.se;
	ll r=arr[a].fi.fi+arr[b].fi.fi;
	return (dx*dx<=r*r-dy*dy);
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&arr[i].se.fi,&arr[i].se.se,&arr[i].fi.fi);
		arr[i].fi.se=-i;
		pq.insert(arr[i]);
	}
	memset(ans,-1,sizeof(ans));
	downscale();
	while(!pq.empty()){
		auto it=pq.end();--it;
		i4 cur=(*it);pq.erase(it);
		int index=-cur.fi.se;
		if(ans[index]!=-1)continue;
		ans[index]=index;
		while(scale>cur.fi.fi){
			downscale();
		}
		int x=cur.se.fi/scale,y=cur.se.se/scale;
		for(int i=x-2;i<=x+2;i++){
			int l=lower_bound(m[i].begin(),m[i].end(),mp(y-2,-INF))-m[i].begin();
			int r=lower_bound(m[i].begin(),m[i].end(),mp(y+3,-INF))-m[i].begin()-1;
			for(int j=l;j<=r;j++){
				int idx=m[i][j].se;
				if(ans[idx]==-1&&intersect(idx,index)){
					i4 link=arr[idx];
					pq.erase(link);
					ans[idx]=index;
				}
			}
		}
	}
	for(int i=0;i<n;i++)printf("%d ",ans[i]+1);
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
circle_selection.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%d%d%d",&arr[i].se.fi,&arr[i].se.se,&arr[i].fi.fi);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1408 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Incorrect 1 ms 1364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 510 ms 35336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2064 ms 39608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1408 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Incorrect 1 ms 1364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1408 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Incorrect 1 ms 1364 KB Output isn't correct
4 Halted 0 ms 0 KB -