#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
#endif
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int INF = 1e9;
const int MOD = 1e9 + 7;
struct DSU {
vector<int> par, sz;
int c; // connected components
DSU(int n) : par(n), c(n) {
sz.resize(n, 1);
for (int i = 0; i < n; ++i) par[i] = i;
}
int find(int i) {
return par[i] == i ? i : (par[i] = find(par[i]));
}
bool same(int i, int j) {
return find(i) == find(j);
}
int get_size(int i) {
return sz[find(i)];
}
int count() {
return c;
}
int merge(int i, int j) {
if ((i = find(i)) == (j = find(j))) return -1;
else --c;
if (sz[i] > sz[j]) swap(i, j);
par[i] = j;
sz[j] += sz[i];
return j;
}
};
struct Point{
int x, y, r;
};
void solve(){
int n, q;
cin >> n >> q;
int w, h;
cin >> w >> h;
vector<Point> a(n);
vector<array<ll, 3>> e;
auto distance = [&](ll x1, ll y1, ll x2, ll y2, ll r1, ll r2){
return (ll)sqrt(abs(x1 - x2) * abs(x1 - x2) + abs(y1 - y2) * abs(y1 - y2)) - r1 - r2;
};
F0R(i, n){
cin >> a[i].x >> a[i].y >> a[i].r;
e.push_back({distance(a[i].x, a[i].y, a[i].x, 0, a[i].r, 0), i + 4, 0});
e.push_back({distance(a[i].x, a[i].y, a[i].x, h, a[i].r, 0), i + 4, 1});
e.push_back({distance(a[i].x, a[i].y, 0, a[i].y, a[i].r, 0), i + 4, 2});
e.push_back({distance(a[i].x, a[i].y, w, a[i].y, a[i].r, 0), i + 4, 3});
}
F0R(i, n)
FOR(j, i + 1, n)
e.push_back({distance(a[i].x, a[i].y, a[j].x, a[j].y, a[i].r, a[j].r), i + 4, j + 4});
vpi que(q);
vi id(q); F0R(i, q) id[i] = i;
F0R(i, q){
cin >> que[i].f >> que[i].s;
que[i].f <<= 1;
}
sort(all(id), [&](int i, int j){return que[i].f < que[j].f;});
sort(all(e));
dbg(e)
DSU dsu(n + 4);
int j = 0;
vector<vector<bool>> ans(q);
F0R(i, q){
dbg(i, j)
dbg(j, e[j][0], que[id[i]].f)
while(j < sz(e) && e[j][0] < que[id[i]].f){
dsu.merge(e[j][1], e[j][2]);
j++;
}
dbg(j, e[j][0], que[id[i]].f)
auto calculate = [&](int a, int b, int c, int d) -> vector<bool>{
vector<bool> ans(4, false);
if(dsu.same(a, c))
return ans;
if(!dsu.same(b, a) && !dsu.same(a, d))
ans[b] = true;
if(!dsu.same(b, a) && !dsu.same(c, d) && !dsu.same(b, d))
ans[c] = true;
if(!dsu.same(c, d) && !dsu.same(c, b))
ans[d] = true;
return ans;
};
if(que[id[i]].s == 1)
ans[i] = calculate(0, 1, 2, 3), ans[i][que[id[i]].s - 1] = true;
else if(que[id[i]].s == 2)
ans[i] = calculate(0, 1, 3, 2), ans[i][que[id[i]].s - 1] = true;
else if(que[id[i]].s == 3)
ans[i] = calculate(1, 0, 2, 3), ans[i][que[id[i]].s - 1] = true;
else if(que[id[i]].f == 4)
ans[i] = calculate(1, 0, 3, 2), ans[i][que[id[i]].s - 1] = true;
}
F0R(i, q){
F0R(j, 4) if(ans[i][j])
cout << j + 1;
cout << nl;
}
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int TC = 1;
// cin >> TC;
while(TC--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
265 ms |
49824 KB |
Output is correct |
2 |
Incorrect |
265 ms |
49916 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
35 ms |
17608 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
265 ms |
49824 KB |
Output is correct |
2 |
Incorrect |
265 ms |
49916 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |