Submission #367917

# Submission time Handle Problem Language Result Execution time Memory
367917 2021-02-18T19:53:53 Z ACmachine Park (BOI16_park) C++17
100 / 100
674 ms 30004 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename U> using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<str> vstr;

#define FOR(i,j,k,in) for(int i=(j); i < (k);i+=in)
#define FORD(i,j,k,in) for(int i=(j); i >=(k);i-=in)
#define REP(i,b) FOR(i,0,b,1)
#define REPD(i,b) FORD(i,b,0,1)
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define rsz resize 
#define MANY_TESTS int tcase; cin >> tcase; while(tcase--)
	
const double EPS = 1e-6;
const int MOD = 1e9+7; // 998244353;
const ll INFF = 1e18;
const int INF = 1e9;
const ld PI = acos((ld)-1);
const vi dy = {1, 0, -1, 0, -1, 1, 1, -1};
const vi dx = {0, 1, 0, -1, -1, 1, -1, 1};

#ifdef DEBUG
#define DBG if(1)
#else
#define DBG if(0)
#endif

#define dbg(x) cout << "(" << #x << " : " << x << ")" << endl;
// ostreams
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U> &par) {out << "[" << par.first << ";" << par.second << "]"; return out;}
template <class T>
ostream& operator<<(ostream& out, const set<T> &cont) { out << "{"; for( const auto &x:cont) out << x << ", "; out << "}"; return out; }
template <class T, class U>
ostream& operator<<(ostream& out, const map<T, U> &cont) {out << "{"; for( const auto &x:cont) out << x << ", "; out << "}"; return out; }
template<class T>
ostream& operator<<(ostream& out, const vector<T> &v){ out << "[";  REP(i, v.size()) out << v[i] << ", ";  out << "]"; return out;}
// istreams
template<class T>
istream& operator>>(istream& in, vector<T> &v){ for(auto &x : v) in >> x; return in; }
template<class T, class U>
istream& operator>>(istream& in, pair<T, U> &p){ in >> p.ff >> p.ss; return in; }
//searches
template<typename T, typename U>
T bsl(T lo, T hi, U f){ hi++; T mid; while(lo < hi){ mid = (lo + hi)/2; f(mid) ? hi = mid : lo = mid+1; } return lo; }
template<typename U>
double bsld(double lo, double hi, U f, double p = 1e-9){ int r = 3 + (int)log2((hi - lo)/p); double mid; while(r--){ mid = (lo + hi)/2; f(mid) ? hi = mid : lo = mid; } return (lo + hi)/2; }
template<typename T, typename U>
T bsh(T lo, T hi, U f){ lo--; T mid; while(lo < hi){ mid = (lo + hi + 1)/2; f(mid) ? lo = mid : hi = mid-1; } return lo; }
template<typename U>
double bshd(double lo, double hi, U f, double p = 1e-9){ int r = 3+(int)log2((hi - lo)/p); double mid; while(r--){ mid = (lo + hi)/2; f(mid) ? lo = mid : hi = mid; } return (lo + hi)/2; }
// some more utility functions
template<typename T>
pair<T, int> get_min(vector<T> &v){ typename vector<T> :: iterator it = min_element(v.begin(), v.end()); return mp(*it, it - v.begin());}
template<typename T>
pair<T, int> get_max(vector<T> &v){ typename vector<T> :: iterator it = max_element(v.begin(), v.end()); return mp(*it, it - v.begin());}        
template<typename T> bool ckmin(T& a, const T& b){return b < a ? a = b , true : false;}
template<typename T> bool ckmax(T& a, const T& b){return b > a ? a = b, true : false;}

ll SQRT(ll x){
    int l = 1;
    int r = 1e9;
    int ans = 0;
    while(l <= r){
        ll mid = (l + r) >> 1;
        if(mid * mid <= x) {
            ans = mid;
            l = mid + 1;
        }
        else{
            r = mid - 1;
        }
    }
    return ans;
}
vector<int> reach;
struct dsu{
    int n;
    vector<int> p;
    vector<int> touches;
    dsu(int _n) : n(_n){
        p.resize(n, -1); 
        touches.resize(n, 0);
    }
    int find(int x){
        return (p[x] < 0 ? x : (p[x] = find(p[x])));
    }
    void join(int u, int v){
        int a = find(u);
        int b = find(v);
        if(a == b) return;
        if(p[a] > p[b]) swap(a, b);
        p[a] += p[b]; p[b] = a;
        touches[a] |= touches[b];
        REP(j, 4){
            if((touches[a] & (1 << j)) && (touches[a] & (1 << ((j + 1) % 4)))){
                reach[j] = (1 << j); 
                REP(k, 4){
                    if(k == j) continue;
                    reach[k] &= (15 - (1 << j));
                }
            }
        }
        if((touches[a] & 1) && (touches[a] & 4)){
            reach[0] &= 3; reach[1] &= 3;
            reach[2] &= 12; reach[3] &= 12;
        }
        if((touches[a]&2) && (touches[a] & 8)){
            reach[0] &= 9; reach[3] &= 9;
            reach[1] &= 6; reach[2] &= 6;
        }
    }
};  
int main(){
 	ios_base::sync_with_stdio(false);
 	cin.tie(NULL); cout.tie(NULL);
    reach = vector<int>(4, 15); 
	int n, m;
    cin >> n >> m;
    int w, h;
    cin >> w >> h;
    struct circle{
        int x, y, r, id; 
        bool operator<(circle &oth){
            return tie(x, y, r, id) < tie(oth.x, oth.y, oth.r, oth.id);
        }
        bool operator==(circle &oth){
            return tie(x, y, r, id) == tie(oth.x, oth.y, oth.r, oth.id);
        }
    };
    vector<circle> trees(n);
    REP(i, n){
        cin >> trees[i].x >> trees[i].y >> trees[i].r;
        trees[i].id = i;
    }
    struct ev{
        int t;
        int u, v;
        bool operator<(ev &oth){
            return tie(t, u, v) < tie(oth.t, oth.u, oth.v);
        }
    };
    vector<ev> events;
    REP(i, trees.size()){
        REP(j, i){
            ll dx = abs(trees[i].x - trees[j].x);
            ll dy = abs(trees[i].y - trees[j].y);
            ll dist = dx * dx + dy * dy;
            ll re = SQRT(dist);
            int t = re - trees[i].r - trees[j].r;
            t++;
            events.pb({t, i, j});
        }
    }
    dsu d(5 * n);
    int up = trees.size();
    int cid = up;
    REP(j, up){
        events.pb({trees[j].y - trees[j].r + 1, j, cid});
        d.touches[cid] |= 2; cid++;
        events.pb({h - trees[j].y - trees[j].r + 1, j, cid});
        d.touches[cid] |= 8; cid++;
        events.pb({trees[j].x - trees[j].r + 1, j, cid});
        d.touches[cid] |= 1; cid++;
        events.pb({w - trees[j].x - trees[j].r + 1, j, cid});
        d.touches[cid] |= 4; cid++; 
    }
    sort(all(events)); 
    struct query{
        int r, e, id;
        bool operator<(query &oth){
            return tie(r, e, id) < tie(oth.r, oth.e, oth.id);
        }
    };
    vector<query> queries(m);
    REP(i, m){
        cin >> queries[i].r >> queries[i].e;
        queries[i].r *= 2;
        queries[i].e--;
        queries[i].id = i;
    }
    sort(all(queries));
    vector<string> ans(m, "");
    int pp = 0;
    REP(j, queries.size()){
        while(pp < events.size() && events[pp].t <= queries[j].r){
            d.join(events[pp].u, events[pp].v);
            pp++;
        }
        int v = queries[j].e;
        REP(i, 4){
            if(reach[v]&(1 << i)) 
                ans[queries[j].id] += (char)('1' + i);
        }
    }
    REP(i, m) cout << ans[i] << "\n";
    return 0;
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:26:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::circle>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 | #define FOR(i,j,k,in) for(int i=(j); i < (k);i+=in)
      |                                        ^
park.cpp:28:18: note: in expansion of macro 'FOR'
   28 | #define REP(i,b) FOR(i,0,b,1)
      |                  ^~~
park.cpp:168:5: note: in expansion of macro 'REP'
  168 |     REP(i, trees.size()){
      |     ^~~
park.cpp:26:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 | #define FOR(i,j,k,in) for(int i=(j); i < (k);i+=in)
      |                                        ^
park.cpp:28:18: note: in expansion of macro 'FOR'
   28 | #define REP(i,b) FOR(i,0,b,1)
      |                  ^~~
park.cpp:209:5: note: in expansion of macro 'REP'
  209 |     REP(j, queries.size()){
      |     ^~~
park.cpp:210:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::ev>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  210 |         while(pp < events.size() && events[pp].t <= queries[j].r){
      |               ~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 634 ms 25152 KB Output is correct
2 Correct 627 ms 25152 KB Output is correct
3 Correct 636 ms 25152 KB Output is correct
4 Correct 628 ms 25280 KB Output is correct
5 Correct 629 ms 25152 KB Output is correct
6 Correct 634 ms 25152 KB Output is correct
7 Correct 585 ms 25152 KB Output is correct
8 Correct 573 ms 25280 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 5352 KB Output is correct
2 Correct 51 ms 6376 KB Output is correct
3 Correct 52 ms 6376 KB Output is correct
4 Correct 49 ms 6376 KB Output is correct
5 Correct 50 ms 6504 KB Output is correct
6 Correct 53 ms 6504 KB Output is correct
7 Correct 45 ms 6144 KB Output is correct
8 Correct 44 ms 6124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 634 ms 25152 KB Output is correct
2 Correct 627 ms 25152 KB Output is correct
3 Correct 636 ms 25152 KB Output is correct
4 Correct 628 ms 25280 KB Output is correct
5 Correct 629 ms 25152 KB Output is correct
6 Correct 634 ms 25152 KB Output is correct
7 Correct 585 ms 25152 KB Output is correct
8 Correct 573 ms 25280 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 52 ms 5352 KB Output is correct
12 Correct 51 ms 6376 KB Output is correct
13 Correct 52 ms 6376 KB Output is correct
14 Correct 49 ms 6376 KB Output is correct
15 Correct 50 ms 6504 KB Output is correct
16 Correct 53 ms 6504 KB Output is correct
17 Correct 45 ms 6144 KB Output is correct
18 Correct 44 ms 6124 KB Output is correct
19 Correct 670 ms 29876 KB Output is correct
20 Correct 674 ms 30004 KB Output is correct
21 Correct 673 ms 29872 KB Output is correct
22 Correct 673 ms 29740 KB Output is correct
23 Correct 671 ms 29732 KB Output is correct
24 Correct 631 ms 29860 KB Output is correct