Submission #1313188

#TimeUsernameProblemLanguageResultExecution timeMemory
1313188faricaPark (BOI16_park)C++20
100 / 100
302 ms25992 KiB
#include<bits/stdc++.h> using namespace std; using vi = vector<int>; using pi = pair<int,int>; typedef long long ll; #define debug(x) cout << #x << " = " << x << "\n"; #define vdebug(a) cout << #a << " = "; for(auto x: a) cout << x << " "; cout << "\n"; const int MOD = 998244353; const int INF = 1e9; template<ll mod> struct modnum { static constexpr bool is_big_mod = mod > numeric_limits<int>::max(); using S = conditional_t<is_big_mod, ll, int>; using L = conditional_t<is_big_mod, __int128, ll>; S x; modnum() : x(0) {} modnum(ll _x) { _x %= static_cast<ll>(mod); if (_x < 0) { _x += mod; } x = _x; } modnum pow(ll n) const { modnum res = 1; modnum cur = *this; while (n > 0) { if (n & 1) res *= cur; cur *= cur; n /= 2; } return res; } modnum inv() const { return (*this).pow(mod-2); } modnum& operator+=(const modnum& a){ x += a.x; if (x >= mod) x -= mod; return *this; } modnum& operator-=(const modnum& a){ if (x < a.x) x += mod; x -= a.x; return *this; } modnum& operator*=(const modnum& a){ x = static_cast<L>(x) * a.x % mod; return *this; } modnum& operator/=(const modnum& a){ return *this *= a.inv(); } friend modnum operator+(const modnum& a, const modnum& b){ return modnum(a) += b; } friend modnum operator-(const modnum& a, const modnum& b){ return modnum(a) -= b; } friend modnum operator*(const modnum& a, const modnum& b){ return modnum(a) *= b; } friend modnum operator/(const modnum& a, const modnum& b){ return modnum(a) /= b; } friend bool operator==(const modnum& a, const modnum& b){ return a.x == b.x; } friend bool operator!=(const modnum& a, const modnum& b){ return a.x != b.x; } friend bool operator<(const modnum& a, const modnum& b){ return a.x < b.x; } friend ostream& operator<<(ostream& os, const modnum& a){ os << a.x; return os; } friend istream& operator>>(istream& is, modnum& a) { ll x; is >> x; a = modnum(x); return is; } }; using mint = modnum<MOD>; template <class T> class SumSegmentTree { private: const T DEFAULT = 0; vector<T> segtree; int len; public: SumSegmentTree(int len) : len(len), segtree(len * 2, DEFAULT) {} void set(int ind, T val) { ind += len; segtree[ind] = val; for (; ind > 1; ind /= 2) { segtree[ind / 2] = segtree[ind] + segtree[ind ^ 1]; } } T range_sum(int start, int end) { T sum = DEFAULT; for (start += len, end += len; start < end; start /= 2, end /= 2) { if (start % 2 == 1) { sum += segtree[start++]; } if (end % 2 == 1) { sum += segtree[--end]; } } return sum; } }; struct BIT { vector<ll>b; int n; void init(int _n) { n = _n ; b.assign(n+1, 0); } inline int lowbit(int x) { return x & (-x); } void update(int x, ll v) { ++x; for(int i = x ; i <= n ; i += lowbit(i)) b[i] += v; } ll query(int x) { ll ans = 0; ++x; for(int i = x ; i > 0 ; i -= lowbit(i)) ans += b[i]; return ans; } } bit; int gcd(int a, int b, int& x, int& y) { // x*a + y*b = a1 x = 1, y = 0; int x1 = 0, y1 = 1, a1 = a, b1 = b; while (b1) { int q = a1 / b1; tie(x, x1) = make_tuple(x1, x - q * x1); tie(y, y1) = make_tuple(y1, y - q * y1); tie(a1, b1) = make_tuple(b1, a1 - q * b1); } return a1; } int inv_ecd(int a, int m) { int x, y; int g = gcd(a, m, x, y); if(g != 1) return -1; x = (x + m) % m; return x; } ll exp(ll x, ll n) { ll res = 1; while (n > 0) { if (n % 2 == 1) { res = res * x % MOD; } x = x * x % MOD; n /= 2; } return res; } vi prnt, siz; int calc(array<int,3>x, array<int,3>y) { int dist_x = x[0] - y[0], dist_y = x[1] - y[1]; ll dist = 1ll*dist_x*dist_x + 1ll*dist_y*dist_y; int ans = sqrt(dist); if(ans*ans != dist) ++ans; ans -= y[2] + x[2]; return ans; } int find_parent(int x) { return (x == prnt[x] ? x : prnt[x] = find_parent(prnt[x])); } bool is_same_set(int a, int b) { return (find_parent(a) == find_parent(b)); } void unite(int a, int b) { int u = find_parent(a), v = find_parent(b); if(u == v) return; if(siz[v] > siz[u]) swap(u,v); prnt[v] = u; siz[u] += siz[v]; } void solve() { int n, m, w, h; cin >> n >> m >> w >> h; int bottomwall = n, leftwall = n + 1, topwall = n + 2, rightwall = n + 3; int bottomleft = 1, topleft = 8, topright = 4, bottomright = 2; prnt.resize(n+4); siz.resize(n+4); vector<array<int,3>>trees(n); vector<pair<int, pi>>dist; for(int i=0; i<n+4; ++i) { if(i<n) cin >> trees[i][0] >> trees[i][1] >> trees[i][2]; prnt[i] = i; siz[i] = 1; } for(int i=0; i<n; ++i) { for(int j=i+1; j<n; ++j) dist.push_back({calc(trees[i], trees[j]), {i,j}}); dist.push_back({trees[i][0]-trees[i][2], {i, n+1}}); dist.push_back({w-trees[i][0]-trees[i][2], {i, n+3}}); dist.push_back({h-trees[i][1]-trees[i][2], {i, n+2}}); dist.push_back({trees[i][1]-trees[i][2], {i, n}}); } sort(dist.begin(), dist.end()); vector<pair<pi, int>>q(m); for(int i=0; i<m; ++i) { cin >> q[i].first.first >> q[i].first.second; q[i].second = i; } sort(q.begin(), q.end()); int ptr = 0; vi ans(m); for(pair<pi,int>tmp: q) { int r = tmp.first.first, c = tmp.first.second; while(ptr != (int)dist.size() && dist[ptr].first <= 2*r) { unite(dist[ptr].second.first, dist[ptr].second.second); ++ptr; } --c; c = (1<<c); int qans = 1|2|4|8; if (is_same_set(leftwall, topwall)) { if (c==topleft) qans = topleft; else qans &= ~topleft; } if (is_same_set(topwall, rightwall)) { if (c==topright) qans = topright; else qans &= ~topright; } if (is_same_set(rightwall, bottomwall)) { if (c==bottomright) qans = bottomright; else qans &= ~bottomright; } if (is_same_set(bottomwall, leftwall)) { if (c==bottomleft) qans = bottomleft; else qans &= ~bottomleft; } if (is_same_set(leftwall, rightwall)) { if (c == bottomleft || c == bottomright) qans &= ~(topleft | topright); else qans &= ~(bottomleft | bottomright); } if (is_same_set(topwall, bottomwall)) { if (c == bottomleft || c == topleft) qans &= ~(topright | bottomright); else qans &= ~(bottomleft | topleft); } ans[tmp.second] = qans; } for(int j=0; j<m; ++j) { int qans = ans[j]; for(int i=0; i<4; ++i) { if((1<<i)&qans) cout << i+1; } cout << endl; } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc=1; while(tc--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...