Submission #1096670

#TimeUsernameProblemLanguageResultExecution timeMemory
1096670tuandqPark (BOI16_park)C++17
100 / 100
455 ms71084 KiB
#include <bits/stdc++.h> using namespace std ; typedef long long ll ; typedef long double ld ; typedef pair<int, int> pii ; typedef pair<int, long long> pil ; typedef pair<long long, int> pli ; typedef pair<long long, long long> pll ; typedef vector<int> vi ; typedef vector<long long> vll ; #define bitc(n) (__builtin_popcountll(n)) #define clz(n) (__builtin_clzll(n)) #define ctz(n) (__builtin_ctzll(n)) #define lg(n) (63 - __builtin_clzll(n)) #define MASK(k) (1ll << (k)) #define getbit(n, k) ((n) >> (k) & 1) #define flipbit(n, k) ((n) ^ (1ll << (k))) #define ton(n, k) ((n) | (1ll << (k))) #define toff(n, k) ((n) & ~(1ll << (k))) #define fi first #define se second #define mp make_pair #define eb emplace_back #define lwb lower_bound #define upb upper_bound #define sz(x) (int)(x.size()) #define all(x) x.begin(),x.end() #define taskname "input" template<class X, class Y> bool maximize(X &x, const Y &y) {return (x < y ? x = y, true : false) ;} template<class X, class Y> bool minimize(X &x, const Y &y) {return (x > y ? x = y, true : false) ;} template<class X> void remove_dup(vector<X> &ve) { sort(ve.begin(), ve.end()) ; ve.resize(unique(ve.begin(), ve.end()) - ve.begin()) ; } const ll mod = 1e9 + 7 ; const ll INF = 1e18 ; const int inf = 1e9 ; const int N = 2e3 + 5 ; const int M = 1e5 + 5 ; /* Some Peach Tea Is Great ;-; */ /* Author : Tuandq */ pii b[M] ; int n, m, w, h ; pair<pii, int> a[N] ; namespace sub3 { struct Disjoint { vector<int> lab ; int n ; Disjoint() {} Disjoint(int _n): n(_n) { lab.assign(n + 1, -1) ; } int find_set(int u) { return lab[u] < 0 ? u : (lab[u] = find_set(lab[u])) ; } bool join(int u, int v) { u = find_set(u) ; v = find_set(v) ; if(u != v) { if(lab[u] > lab[v]) swap(u, v) ; lab[u] += lab[v] ; lab[v] = u ; return true ; } return false ; } } dsu ; string res[M] ; ll sq(const int &x) { return 1ll * x * x ; } ld dis(pii u, pii v) { return 1.0 * sqrt(sq(v.fi - u.fi) + sq(v.se - u.se)) ; } void solve() { vector<pair<ld, pii>> edges ; for(int i = 1; i <= n; i ++) { edges.emplace_back(a[i].fi.fi - a[i].se, mp(i, n + 1)) ; edges.emplace_back(a[i].fi.se - a[i].se, mp(i, n + 2)) ; edges.emplace_back(w - a[i].fi.fi - a[i].se, mp(i, n + 3)) ; edges.emplace_back(h - a[i].fi.se - a[i].se, mp(i, n + 4)) ; for(int j = i + 1; j <= n; j ++) { edges.emplace_back(dis(a[i].fi, a[j].fi) - a[i].se - a[j].se, mp(i, j)) ; } } sort(all(edges)) ; vector<int> idx(m) ; iota(all(idx), 1) ; sort(all(idx), [](const int &i, const int &j) { return b[i].fi < b[j].fi ; }) ; dsu = Disjoint(n + 4) ; for(int i = 0, j = 0; i < m; i ++) { while(j < sz(edges) && edges[j].fi < 2.0 * b[idx[i]].fi) { dsu.join(edges[j].se.fi, edges[j].se.se) ; ++ j ; } int &e = b[idx[i]].se ; -- e ; vector<int> h(4) ; h[0] = dsu.find_set(n + 1) ; h[1] = dsu.find_set(n + 2) ; h[2] = dsu.find_set(n + 3) ; h[3] = dsu.find_set(n + 4) ; string &cur = res[idx[i]] = "" ; for(int k = 0; k < 4; k ++) { if(k == e) { cur += (char)(k + '1') ; continue ; } bool flag = false ; flag |= (h[0] == h[2] && getbit(e, 1) != getbit(k, 1)) ; flag |= (h[1] == h[3] && (getbit(e, 0) ^ getbit(e, 1) ^ getbit(k, 0) ^ getbit(k, 1))) ; flag |= (h[e] == h[(e + 1) & 3]) ; flag |= (h[k] == h[(k + 1) & 3]) ; if(!flag) { cur += (char)(k + '1') ; } } } for(int i = 1; i <= m; i ++) { cout << res[i] << '\n' ; } } } signed main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ; if(fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin) ; freopen(taskname".out", "w", stdout) ; } cin >> n >> m >> w >> h ; for(int i = 1; i <= n; i ++) { int x, y, r ; cin >> x >> y >> r ; a[i] = mp(mp(x, y), r) ; } for(int i = 1; i <= m; i ++) { cin >> b[i].fi >> b[i].se ; } return sub3::solve(), 0 ; }

Compilation message (stderr)

park.cpp: In function 'int main()':
park.cpp:153:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  153 |         freopen(taskname".inp", "r", stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:154:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  154 |         freopen(taskname".out", "w", stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...