// #pragma GCC optimize("O3")
// #pragma GCC optimization("Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzd,popd")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, l, r) for (int i = (l); i <= (r); i++)
#define FOD(i, r, l) for (int i = (r); i >= (l); i--)
#define fi first
#define se second
#define pii pair<int, int>
const ll mod = 111539768;
const int MAXN = 1e6 + 5;
const int oo = 1e18 + 7;
const ll base = 320;
int n, m, w, h;
struct cay{
int x, y, r;
}a[MAXN];
struct ng{
int r, e, ps;
string kq;
}b[MAXN];
map<double, vector<pii>> mp;
vector<double> vec;
double kc(int x, int y, int xx, int yy){
return (double(sqrt((double(x-xx)*double(x-xx))+(double(y-yy)*double(y-yy)))));
}
bool cmp(ng a, ng b){
return a.r<b.r;
}
bool cmp2(ng a, ng b){
return a.ps<b.ps;
}
int par[MAXN];
int find(int u){
if(u==par[u]){
return u;
}
return par[u]=find(par[u]);
}
void join(int u, int v){
u=find(u);
v=find(v);
if(u==v){
return;
}
par[v]=u;
}
int chk(int u, int v){
return find(u)==find(v);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("test.txt", "r", stdin);
// freopen("o2.out", "w", stdout);
if(fopen(".inp", "r")){
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> n >> m;
cin >> h >> w;
FOR(i, 5, n+4){
int x, y, r;
cin >> x >> y >> r;
a[i]={x, y, r};
}
FOR(i, 1, m){
int r, c;
cin >> r >> c;
b[i]={r, c, i, ""};
}
FOR(i, 5, n+4){
auto [x, y, r]=a[i];
mp[double(x-r)].push_back({i, 4});
vec.push_back(double(x-r));
mp[double(h-(x+r))].push_back({i, 2});
vec.push_back(double(h-(x+r)));
mp[double(y-r)].push_back({i, 3});
vec.push_back(double(y-r));
mp[double(w-(y+r))].push_back({i, 1});
vec.push_back(double(w-(y+r)));
FOR(j, 5, n+4){
if(i!=j){
auto [x, y, r]=a[i];
auto [xx, yy, rr]=a[j];
mp[kc(x, y, xx, yy)-r-rr].push_back({i, j});
vec.push_back(kc(x, y, xx, yy)-r-rr);
}
}
}
sort(b+1, b+1+m, cmp);
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
FOR(i, 1, n+5){
par[i]=i;
}
for(auto x:vec){
// cout << x << " ";
for(auto [u, v]:mp[x]){
// cout << u << ' ' << v << " ";
// join(u, v);
}
// cout << '\n';
}
int j=0;
FOR(i, 1, m){
auto [r, e, ps, kq]=b[i];
r*=2;
while(j<=vec.size()-1 && vec[j]<r){
// cout << vec[j] << " ";
for(auto [u, v]:mp[vec[j]]){
// cout << u << ' ' << v << " ";
join(u, v);
}
j++;
// cout << '\n';
}
string s=to_string(e);
if(e==1){
if(!chk(3, 4) && !chk(1, 3) && !chk(2, 3)){
s+='2';
}
if(!chk(3, 4) && !chk(1, 3) && !chk(4, 2) && !chk(1, 2)){
s+='3';
}
if(!chk(3, 4) && !chk(2, 4) && !chk(1, 4)){
s+='4';
}
}
else if(e==2){
if(!chk(3, 2) && !chk(1, 3) && !chk(3, 4)){
s+='1';
}
if(!chk(3, 2) && !chk(2, 4) && !chk(1, 2)){
s+='3';
}
if(!chk(3, 2) && !chk(2, 4) && !chk(1, 3) && !chk(1, 4)){
s+='4';
}
}
else if(e==3){
if(!chk(1, 2) && !chk(1, 3) && !chk(2, 4) && !chk(3, 4)){
s+='1';
}
if(!chk(1, 2) && !chk(2, 4) && !chk(3, 2)){
s+='2';
}
if(!chk(1, 2) && !chk(1, 3) && !chk(1, 4)){
s+='4';
}
}
else if(e==4){
if(!chk(1, 4) && !chk(2, 4) && !chk(3, 4)){
s+='1';
}
if(!chk(1, 4) && !chk(2, 4) && !chk(1, 3) && !chk(3, 2)){
s+='2';
}
if(!chk(1, 4) && !chk(1, 3) && !chk(1, 4)){
s+='3';
}
}
// cout << s;
sort(s.begin(), s.end());
b[i].kq=s;
}
sort(b+1, b+1+m, cmp2);
FOR(i, 1, m){
cout << b[i].kq << '\n';
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
park.cpp: In function 'int main()':
park.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | freopen(".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
park.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | freopen(".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |