#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int maxN = 5e6 + 5;
const int Mod = 1e9 + 7;
ll n, h, w;
struct Tdata
{
ll x, y, r;
ll id;
bool operator < (const Tdata& other) const
{
if (x == other.x) return y < other.y;
return x < other.x;
}
bool operator == (const Tdata& other) const
{
return x == other.x && y == other.y;
}
}
p[maxN];
struct Tedge
{
ll u, v;
ll w;
bool operator < (const Tedge& other) const
{
return w < other.w;
}
};
struct Tquery
{
ll r, e;
ll id;
bool operator < (const Tquery& other) const
{
return r < other.r;
}
}
qe[maxN];
vector<Tedge> e;
int q;
void input()
{
cin >> n >> q;
cin >> w >> h;
for (int i = 1; i <= n; ++i) cin >> p[i].x >> p[i].y >> p[i].r;
for (int i = 1; i <= q; ++i)
{
cin >> qe[i].r >> qe[i].e;
qe[i].r *= 2;
qe[i].id = i;
}
sort(qe + 1, qe + q + 1);
}
int m = 0;
void add(int u, int i)
{
ll eu = 0, ev = 0, ew = 0;
eu = i;
ev = u + 4;
if (i == 1) ew = p[u].y - p[u].r;
if (i == 2) ew = w - (p[u].x + p[u].r);
if (i == 3) ew = h - (p[u].y + p[u].r);
if (i == 4) ew = p[u].x - p[u].r;
e.push_back({eu, ev, ew});
}
ll sqr(ll x)
{
return x * x;
}
ll dist(int i, int j)
{
return ll(sqrt(ll(sqr(p[i].x - p[j].x) + sqr(p[i].y - p[j].y)))) - p[i].r - p[j].r;
}
int lab[maxN];
int findset(int u)
{
return lab[u] < 0 ? u : lab[u] = findset(lab[u]);
}
void unite(int u, int v)
{
u = findset(u);
v = findset(v);
if (u == v) return;
if (lab[u] > lab[v]) swap(u, v);
lab[u] += lab[v];
lab[v] = u;
}
bool c[7][7];
string res[maxN];
void calc(int i, int id)
{
string s = "";
if (i == 1)
{
s.push_back('1');
if (!c[1][4])
{
if (!c[1][2] && !c[1][3]) s.push_back('2');
if (!c[2][3] && !c[1][3] && !c[2][4]) s.push_back('3');
if (!c[3][4] && !c[2][4]) s.push_back('4');
}
}
if (i == 2)
{
if (!c[1][2])
{
if (!c[1][4] && !c[1][3]) s.push_back('1');
s.push_back('2');
if (!c[2][4] && !c[2][3]) s.push_back('3');
if (!c[3][4] && !c[1][3] && !c[2][4]) s.push_back('4');
}
else s.push_back('2');
}
if (i == 3)
{
if (!c[2][3])
{
if (!c[1][4] && !c[1][3] && !c[2][4]) s.push_back('1');
if (!c[1][2] && !c[2][4]) s.push_back('2');
s.push_back('3');
if (!c[1][3] && !c[3][4]) s.push_back('4');
}
else s.push_back('3');
}
if (i == 4)
{
if (!c[3][4])
{
if (!c[1][4] && !c[2][4]) s.push_back('1');
if (!c[1][2] && !c[1][3] && !c[2][4]) s.push_back('2');
if (!c[1][3] && !c[2][3]) s.push_back('3');
s.push_back('4');
}
else s.push_back('4');
}
res[id] = s;
}
void solve()
{
for (int i = 1; i <= n; ++i)
for (int d = 1; d <= 4; ++d) add(i, d);
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
e.push_back({i + 4, j + 4, dist(i, j)});
fill(lab + 1, lab + n + 5, -1);
int j = 0;
j = 0;
sort(e.begin(), e.end());
//for (Tedge p : e) cout << p.u << " " << p.v << " " << p.w << "\n";
for (int i = 1; i <= q; ++i)
{
while (j < int(e.size()) && e[j].w < qe[i].r)
{
unite(e[j].u, e[j].v);
++j;
}
for (int x = 1; x <= 4; ++x)
for (int y = 1; y <= 4; ++y)
c[x][y] = (findset(x) == findset(y));
//if (qe[i].id == 2) cout << qe[i].r << " " << c[1][2] << "SDSDSD\n";
calc(qe[i].e, qe[i].id);
//if (qe[i].id == 2) cout << qe[i].r << " " << c[1][4] << " " << qe[i].id << "SDSDSD\n";
}
for (int i = 1; i <= q; ++i) cout << res[i] << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("PARK.inp","r",stdin);
// freopen("PARK.out","w",stdout);
input();
solve();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |