# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
367907 |
2021-02-18T19:31:30 Z |
ACmachine |
Park (BOI16_park) |
C++17 |
|
481 ms |
262148 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-9;
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;
}
int up = trees.size();
int cid = up;
REP(i, up){
trees.pb({0, trees[i].y, 0, cid++});
trees.pb({w, trees[i].y, 0, cid++});
trees.pb({trees[i].x, 0, 0,cid++});
trees.pb({trees[i].x, h, 0, cid++});
}
sort(all(trees));
trees.erase(unique(all(trees)), trees.end());
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));
int t = re - trees[i].r - trees[j].r;
t++;
events.pb({t, i, j});
}
}
/* REP(i, events.size()){ */
/* dbg(events[i].t) */
/* dbg(mp(events[i].u, events[i].v)) */
/* } */
sort(all(events));
dsu d((int)trees.size());
REP(j, trees.size()){
if(trees[j].x == 0) d.touches[j] |= 1;
if(trees[j].y == 0) d.touches[j] |= 2;
if(trees[j].x == w) d.touches[j] |= 4;
if(trees[j].y == h) d.touches[j] |= 8;
}
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:159:5: note: in expansion of macro 'REP'
159 | REP(i, trees.size()){
| ^~~
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:176:5: note: in expansion of macro 'REP'
176 | REP(j, 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:197:5: note: in expansion of macro 'REP'
197 | REP(j, queries.size()){
| ^~~
park.cpp:198:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::ev>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
198 | while(pp < events.size() && events[pp].t <= queries[j].r){
| ~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
481 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
10716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
481 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |