Submission #69217

#TimeUsernameProblemLanguageResultExecution timeMemory
69217MANcityPark (BOI16_park)C++14
100 / 100
1578 ms52588 KiB
///GAGO_O #include<iostream> #include<cstdio> #include<fstream> #include<algorithm> #include<cmath> #include<map> #include<queue> #include<set> #include<stack> #include<string> #include<cstring> #include<vector> using namespace std; #define for1(i,n) for(int i=1;i<=(int)n;i++) #define for0(i,n) for(int i=0;i<=(int)n;i++) #define forn(i,n) for(int i=n;i>=1;i--) #define fo(i,x,y) for(int i=x;i<=(int)y;i++) #define fr(i,x,y) for(int i=x;i>=(int)y;i--) #define pb push_back #define mp make_pair #define LL long long const LL Mod=1000*1000*1000+7; int n,m; LL w,h; LL x[2002],y[2002],rad[2002]; int parent[2002]; int sz[2002]; int make_set(int v) { parent[v]=v; sz[v]=1; } int find_set(int v) { if(v==parent[v]) return v; return parent[v]=find_set(parent[v]); } void union_sets(int a,int b) { a=find_set(a); b=find_set(b); if(a!=b) { if(sz[a]<sz[b]) swap(a,b); parent[b]=a; sz[a]+=sz[b]; } } int hat(int i,int j,LL R) { LL x1=x[i],y1=y[i],r1=rad[i]+R; LL x2=x[j],y2=y[j],r2=rad[j]+R; if(j>n) r2=0; if(j==(n+1)) { x2=R; y2=y1; } if(j==(n+3)) { x2=(w-R); y2=y1; } if(j==(n+2)) { y2=(h-R); x2=x1; } if(j==(n+4)) { y2=R; x2=x1; } LL dist=(LL)(x1-x2)*(x1-x2)+(LL)(y1-y2)*(y1-y2); LL Rsum=(LL)(r1+r2)*(r1+r2); if(Rsum>dist) return 1; return 0; } vector<pair<LL,pair<int,int> > > event; pair<LL,pair<int,int> > query[100002]; int karagna[5][5]; void pox(int i,int j) { karagna[i][j]=0; karagna[j][i]=0; } void stug() { int p[5]; for1(i,4) p[i]=find_set(n+i); if(p[1]==p[2]) { pox(4,1); pox(4,2); pox(4,3); } if(p[1]==p[3]) { pox(4,1); pox(4,2); pox(3,1); pox(3,2); } if(p[1]==p[4]) { pox(1,4); pox(1,3); pox(1,2); } if(p[2]==p[3]) { pox(1,3); pox(4,3); pox(2,3); } if(p[2]==p[4]) { pox(1,2); pox(1,3); pox(4,3); pox(4,2); } if(p[3]==p[4]) { pox(1,2); pox(4,2); pox(3,2); } } string ANS[100002]; int main() { cin>>n>>m; cin>>w>>h; for1(i,n) cin>>x[i]>>y[i]>>rad[i]; for1(i,n) fo(j,i+1,n+4) { LL l=0; LL r=1000000000; while(1) { if(l==r) break; LL m=(l+r)/2; if(hat(i,j,m)==1) r=m; else l=(m+1); } event.push_back({l,{i,j}}); } sort(event.begin(),event.end()); for1(i,n+4) make_set(i); for1(i,m) { cin>>query[i].first>>query[i].second.first; query[i].second.second=i; } sort(query+1,query+m+1); int pos=0; int l=event.size(); for1(i,4) for1(j,4) karagna[i][j]=1; for1(i,m) { int ENT=query[i].second.first; int rpos=query[i].second.second; while(1) { if(pos >= l) break; if(event[pos].first <= query[i].first) { int a=event[pos].second.first; int b=event[pos].second.second; union_sets(a,b); } else break; pos++; } stug(); fo(j,1,4) if(karagna[ENT][j]==1) ANS[rpos]+=(j+'0'); } for1(i,m) cout<<ANS[i]<<endl; return 0; } /* 5 3 16 11 11 8 1 6 10 1 7 3 2 10 4 1 15 5 1 1 1 2 2 2 1 */

Compilation message (stderr)

park.cpp: In function 'int make_set(int)':
park.cpp:33:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...