Submission #367912

# Submission time Handle Problem Language Result Execution time Memory
367912 2021-02-18T19:44:50 Z ACmachine Park (BOI16_park) C++17
0 / 100
371 ms 25280 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;}


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); 
            }
        }
        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 = floor(sqrt((long double)dist) + EPS);
            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, j, cid});
        d.touches[cid] |= 2; cid++;
        events.pb({h - trees[j].y - trees[j].r, j, cid});
        d.touches[cid] |= 8; cid++;
        events.pb({trees[j].x - trees[j].r, j, cid});
        d.touches[cid] |= 1; cid++;
        events.pb({w - trees[j].x - trees[j].r, 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;
    }
    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:149:5: note: in expansion of macro 'REP'
  149 |     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:190:5: note: in expansion of macro 'REP'
  190 |     REP(j, queries.size()){
      |     ^~~
park.cpp:191:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::ev>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  191 |         while(pp < events.size() && events[pp].t <= queries[j].r){
      |               ~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 349 ms 25152 KB Output is correct
2 Incorrect 371 ms 25280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 5352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 349 ms 25152 KB Output is correct
2 Incorrect 371 ms 25280 KB Output isn't correct
3 Halted 0 ms 0 KB -