# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
373045 | alirezasamimi100 | Park (BOI16_park) | C++17 | 0 ms | 0 KiB |
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>
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")
using namespace std;
using ll = long long int;
#define F first
#define S second
#define pb push_back
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=2e3+10,LN=20,M=1e5+10,SQ=350,inf=1e9;
const ll INF=1e18;
const int MOD=1000000007 /*998244353*/;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
ll ans=1;
while (y != 0) {
if (y & 1) ans = ans * x % mod;
y >>= 1;
x = x * x % mod;
}
return ans;
}
ll n,q,w,h,X[N],Y[N],R[N],P[N];
vector<pair<double,pll>> ed;
vector<pair<pair<double,ll>,ll>> qu;
vector<ll> ans[M];
ll gp(ll x){
return P[x]?P[x]=gp(P[x]):x;
}
void uni(ll v, ll u){
v=gp(v),u=gp(u);
if(v!=u) P[u]=v;
}
int main(){
fast_io;
cin >> n >> q >> w >> h;
for(ll i=1; i<=n; i++){
cin >> X[i] >> Y[i] >> R[i];
ed.pb({X[i]-R[i],{i,n+1}});
ed.pb({Y[i]-R[i],{i,n+2}});
ed.pb({w-X[i]-R[i],{i,n+3}});
ed.pb({h-Y[i]-R[i],{i,n+4}});
}
for(ll i=1; i<=n; i++){
for(ll j=i+1; j<=n; j++){
ll x=X[i]-X[j],y=Y[i]-Y[j],r=R[i]+R[j];
ed.pb({sqrt(1.0*x*x+y*y)-r,{i,j}});
}
}
sort(ed.begin(),ed.end());
ll j=0;
for(ll i=1; i<=q; i++){
ll r,e;
cin >> r >> e;
qu.pb({{2*r,e},i});
}
sort(qu.begin(),qu.end());
for(ll i=0; i<q; i++){
ll e=qu[i].F.S,k=qu[i].S;
while(j<ed.size() && ed[j].F<qu[i].F.F){
uni(ed[j].S.F,ed[j].S.S);
j++;
}
if(e==1){
ans[k].pb(1);
ll p[5];
for(ll x=1; x<5; x++) p[x]=gp(n+x);
if(p[2]!=p[1] && p[2]!=p[3] && p[2]!=p[4]) ans[k].pb(2);
if(p[1]!=p[2] && p[1]!=p[3] && p[1]!=p[4]) ans[k].pb(4);
if(p[1]!=p[2] && p[1]!=p[3] && p[4]!=p[3] && p[4]!=p[2]) ans[k].pb(3);
}
if(e==2){
ans[k].pb(2);
ll p[5];
for(ll x=1; x<5; x++) p[x]=gp(n+x);
if(p[3]!=p[1] && p[3]!=p[4] && p[3]!=p[1]) ans[k].pb(3);
if(p[2]!=p[1] && p[2]!=p[3] && p[2]!=p[4]) ans[k].pb(1);
if(p[3]!=p[2] && p[3]!=p[1] && p[4]!=p[2] && p[4]!=p[1]) ans[k].pb(2);
}
if(e==3){
ans[k].pb(3);
ll p[5];
for(ll x=1; x<5; x++) p[x]=gp(n+x);
if(p[4]!=p[1] && p[4]!=p[2] && p[4]!=p[3]) ans[k].pb(4);
if(p[3]!=p[2] && p[3]!=p[4] && p[3]!=p[1]) ans[k].pb(2);
if(p[2]!=p[1] && p[2]!=p[4] && p[3]!=p[1] && p[3]!=p[4]) ans[k].pb(1);
}
if(e==4){
ans[k].pb(4);
ll p[5];
for(ll x=1; x<5; x++) p[x]=gp(n+x);
if(p[1]!=p[2] && p[1]!=p[3] && p[1]!=p[4]) ans[k].pb(1);
if(p[4]!=p[2] && p[4]!=p[1] && p[4]!=p[3]) ans[k].pb(3);
if(p[1]!=p[4] && p[1]!=p[3] && p[2]!=p[3] && p[2]!=p[4]) ans[k].pb(2);
}
sort(ans[k].begin(),ans[k].end());
}
for(ll i=1; i<=q; i++){
for(ll j : ans[i]) cout << j;
cout << '\n';
}
return 0;
}