# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1096420 |
2024-10-04T12:20:07 Z |
anhthi |
Park (BOI16_park) |
C++14 |
|
622 ms |
52048 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
template <class X, class Y>
inline bool maximize(X &x, Y y) {
return (x < y ? x = y, true : false);
}
template <class X, class Y>
inline bool minimize(X &x, Y y) {
return (x > y ? x = y, true : false);
}
template <class X>
inline void compress(vector<X> &a) {
sort(all(a));
a.resize(unique(all(a)) - a.begin());
}
int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
return l + abs((ll) rng()) % (r - l + 1);
}
const ll oo = (ll) 1e17;
const int inf = (ll) 2e9 + 7, mod = (ll) 123456789;
const int N = 1e5 + 15, BASE = 307;
void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
ll n, q, w, h;
ll x[N], y[N], r[N];
array<ll, 3> query[N];
vector<array<ll, 3>> e;
ll sqr(ll x) { return x * x; }
ll dist(int i, int j) {
ll cur = sqr(x[i] - x[j]) + sqr(y[i] - y[j]);
ll l = 0, h = 2e9;
while(l < h){
ll mid = (l + h + 1) >> 1;
if (sqr(mid) <= cur) l = mid;
else h = mid - 1;
}
return l - r[i] - r[j];
}
struct dsu {
vector<ll> par, sz;
dsu(ll n) {
par.resize(n + 15);
sz.resize(n + 15, 1);
rep(i, n) par[i] = i;
}
ll root(ll u) {
return u == par[u] ? u : par[u] = root(par[u]);
}
void unite(ll u, ll v) {
u = root(u);
v = root(v);
if (u == v) return;
if (sz[u] < sz[v])
swap(u, v);
par[v] = u;
sz[u] += sz[v];
return;
}
bool connect(ll u, ll v) {
return root(u) == root(v);
}
};
bool res[N][5];
vector<pair<ll, ll>> state[5][5];
signed main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q >> w >> h;
forn(i, 1, n) {
cin >> x[i] >> y[i] >> r[i];
e.pb({x[i] - r[i], n + 1, i});
e.pb({h - y[i] - r[i], n + 2, i});
e.pb({w - x[i] - r[i], n + 3, i});
e.pb({y[i] - r[i], n + 4, i});
}
forn(i, 1, n) forn(j, i + 1, n) e.pb({dist(i, j), i, j});
sort(all(e));
// for (auto x : e) cout << x[1] << ' ' << x[2] << ' ' << x[0] << '\n';
rep(i, q) {
int r, pos;
cin >> r >> pos;
query[i] = {2 * r, pos, i};
}
sort(query + 1, query + 1 + q);
// forn(i, 1, q) cout << query[i][0] << ' ' << query[i][1] << ' ' << query[i][2] << '\n';
state[1][2] = { {n + 2, n + 4}, {n + 1, n + 4}, {n + 4, n + 3} };
state[1][3] = { {n + 1, n + 3}, {n + 4, n + 2}, {n + 2, n + 3}, {n + 1, n + 4} };
state[1][4] = { {n + 1, n + 3}, {n + 1, n + 4}, {n + 1, n + 2} };
state[2][3] = { {n + 1, n + 3}, {n + 4, n + 3}, {n + 3, n + 2} };
state[2][4] = { {n + 1, n + 3}, {n + 2, n + 4}, {n + 4, n + 3}, {n + 1, n + 2} };
state[3][4] = { {n + 2, n + 3}, {n + 2, n + 4}, {n + 1, n + 2} };
ll ID = 0;
dsu d(n + 4);
forn(i, 1, q) {
array<ll, 3> cur = query[i];
for (; ID < sz(e) && e[ID][0] < cur[0]; ++ID)
d.unite(e[ID][1], e[ID][2]);
forn(nxt, 1, 4) {
bool ok = true;
int u = min(1LL * nxt, cur[1]);
int v = max(1LL * nxt, cur[1]);
for (pair<ll, ll> tmp : state[u][v]) {
if (d.connect(tmp.first, tmp.second)) {
ok = false; break;
}
}
res[cur[2]][nxt] = ok;
}
}
rep(i, q) {
forn(j, 1, 4) if (res[i][j]) cout << j;
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
579 ms |
50032 KB |
Output is correct |
2 |
Correct |
580 ms |
49796 KB |
Output is correct |
3 |
Correct |
576 ms |
49796 KB |
Output is correct |
4 |
Correct |
570 ms |
49800 KB |
Output is correct |
5 |
Correct |
572 ms |
49800 KB |
Output is correct |
6 |
Correct |
586 ms |
49772 KB |
Output is correct |
7 |
Correct |
526 ms |
49672 KB |
Output is correct |
8 |
Correct |
526 ms |
49836 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
4200 KB |
Output is correct |
2 |
Correct |
37 ms |
5320 KB |
Output is correct |
3 |
Correct |
42 ms |
5408 KB |
Output is correct |
4 |
Correct |
39 ms |
5320 KB |
Output is correct |
5 |
Correct |
49 ms |
5320 KB |
Output is correct |
6 |
Correct |
42 ms |
5288 KB |
Output is correct |
7 |
Correct |
32 ms |
4692 KB |
Output is correct |
8 |
Correct |
33 ms |
4780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
579 ms |
50032 KB |
Output is correct |
2 |
Correct |
580 ms |
49796 KB |
Output is correct |
3 |
Correct |
576 ms |
49796 KB |
Output is correct |
4 |
Correct |
570 ms |
49800 KB |
Output is correct |
5 |
Correct |
572 ms |
49800 KB |
Output is correct |
6 |
Correct |
586 ms |
49772 KB |
Output is correct |
7 |
Correct |
526 ms |
49672 KB |
Output is correct |
8 |
Correct |
526 ms |
49836 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
50 ms |
4200 KB |
Output is correct |
12 |
Correct |
37 ms |
5320 KB |
Output is correct |
13 |
Correct |
42 ms |
5408 KB |
Output is correct |
14 |
Correct |
39 ms |
5320 KB |
Output is correct |
15 |
Correct |
49 ms |
5320 KB |
Output is correct |
16 |
Correct |
42 ms |
5288 KB |
Output is correct |
17 |
Correct |
32 ms |
4692 KB |
Output is correct |
18 |
Correct |
33 ms |
4780 KB |
Output is correct |
19 |
Correct |
605 ms |
51792 KB |
Output is correct |
20 |
Correct |
622 ms |
51932 KB |
Output is correct |
21 |
Correct |
615 ms |
52048 KB |
Output is correct |
22 |
Correct |
610 ms |
51900 KB |
Output is correct |
23 |
Correct |
617 ms |
51864 KB |
Output is correct |
24 |
Correct |
555 ms |
52048 KB |
Output is correct |