#include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for(int i = (l); i < (r); ++i)
#define ROF(i, l, r) for(int i = (l) - 1; i >= (r); --i)
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define sz(v) (int)v.size()
#define sum_of(v) accumulate(all(v), 0ll)
#define pb push_back
#define eb emplace_back
#define compact(v) v.erase(unique(all(v)), end(v))
#define dbg(x) "[" #x " = " << (x) << "]"
#define file(task) if(fopen(task".inp", "r")){ \
freopen(task".inp", "r", stdin); \
freopen(task".out", "w", stdout); }
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true;
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true;
return false;
}
using ll = long long;
using db = double;
using ld = long double;
using ull = unsigned long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vd = vector<db>;
using vpi = vector<pi>;
using vpl = vector<pl>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct point{
ll x, y;
point() : x(0), y(0) {}
point(ll x, ll y) : x(x), y(y){ }
point& operator += (const point& o){
x += o.x; y += o.y;
return *this;
}
point& operator -= (const point& o){
x -= o.x; y -= o.y;
return *this;
}
point& operator *= (const ll& o){
x *= o; y *= o;
return *this;
}
point& operator /= (const ll& o){
x /= o; y /= o;
return *this;
}
friend point operator + (point a, const point& b){ return a += b; }
friend point operator - (point a, const point& b){ return a -= b; }
friend point operator * (point a, const ll& b){ return a *= b; }
friend point operator / (point a, const ll& b){ return a /= b; }
friend bool operator == (const point& a, const point& b){ return a.x == b.x && a.y == b.y; }
friend bool operator != (const point& a, const point& b){ return a.x != b.x || a.y != b.y; }
friend istream& operator >> (istream& in, point& o){ return in >> o.x >> o.y; }
friend ostream& operator << (ostream& out, const point& o){ return out << '(' << o.x << ',' << o.y << ')'; }
bool operator < (const point& o){ return make_pair(x, y) < make_pair(o.x, o.y); }
};
ll cross(const point& a, const point& b){
return a.x * b.y - a.y * b.x;
}
ll cross3(const point& a, point b, point c){
return cross(b - a, c - a);
}
ll dot(const point& a, const point& b){
return a.x * b.x + a.y * b.y;
}
ll dot3(const point& a, point b, point c){
return dot(b - a, c - a);
}
int sign(ll x){
if(x < 0) return -1;
if(x > 0) return +1;
return 0;
}
bool point_on_segment(const point& a, const point& b, const point& c){ //C on AB
return cross3(a, b, c) == 0 && dot3(c, a, b) <= 0;
}
bool intersect_two_segments(const point& a, const point& b, const point& c, const point& d, bool strictly){
if(!strictly)
if(point_on_segment(a, b, c) || point_on_segment(a, b, d) || point_on_segment(c, d, a) || point_on_segment(c, d, b)) return true;
return sign(cross3(a, b, c)) * sign(cross3(a, b, d)) < 0 && sign(cross3(c, d, a)) * sign(cross3(c, d, b)) < 0;
}
const double inf = 4e18;
struct line{
ll a, b;
line(ll a = 0, ll b = 0) : a(a), b(b) {}
double eval(double x){ return a * x + b; }
bool operator < (const line& d){ return a < d.a; }
};
struct ConvexHullTrick{
vector<line> v;
ConvexHullTrick() : v() {}
double inter(const line& d1, const line& d2){
return 1.0 * (d2.b - d1.b) / (d1.a - d2.a);
}
void insert(ll a, ll b){
line d(a, b);
if(!v.empty() && v.back().a == a){
if(v.back().b <= b) return;
v.pop_back();
}
while(sz(v) > 1 && inter(v[sz(v) - 2], v.back()) >= inter(v.back(), d)){
v.pop_back();
} v.pb(d);
}
double query(double x){
int l = 0, r = sz(v) - 1;
while(l < r){
int mid = l + r >> 1;
if(v[mid].eval(x) >= v[mid + 1].eval(x)) l = mid + 1;
else r = mid;
}
return v[l].eval(x);
}
};
tuple<ll, ll, ll> line_equation_form(const point& P, const point& Q){
ll a = Q.y - P.y;
ll b = P.x - Q.x;
ll c = -cross(P, Q);
if(b < 0) a = -a, b = -b, c = -c;
return mt(a, b, c);
}
void testcase(int num_testcase){
int N;
cin >> N;
vector<point> pts(N);
FOR(i, 0, N) cin >> pts[i];
int M;
cin >> M;
vector<point> polygon(N);
FOR(i, 0, M) cin >> polygon[i];
sort(rall(polygon));
ConvexHullTrick min_hull, max_hull;
FOR(i, 0, M) min_hull.insert(polygon[i].x, polygon[i].y);
ROF(i, M, 0) max_hull.insert(-polygon[i].x, -polygon[i].y);
ll max_x = polygon.front().x, min_x = polygon.back().x;
auto check = [&](const point& P, const point& Q) -> bool{
ll a, b, c; tie(a, b, c) = line_equation_form(P, Q);
// cout << dbg(a) << dbg(b) << dbg(c) << '\n';
if(b == 0){
ll mn_eval = min(min_x * a, max_x * a) + c;
ll mx_eval = max(min_x * a, max_x * a) + c;
if(mn_eval == 0 || mx_eval == 0) return true;
if(sign(mn_eval) == sign(mx_eval)) return true;
return false;
} else{
double frac = 1.0 * a / b;
ll mn_eval = (1.0 * min_hull.query(frac) * b) + c;
ll mx_eval = (-1.0 * max_hull.query(frac) * b) + c;
if(mn_eval == 0 || mx_eval == 0) return true;
if(sign(mn_eval) == sign(mx_eval)) return true;
return false;
}
return true;
};
vi vis(N);
vi mark(N, 0);
FOR(i, 1, N){
if(check(pts[0], pts[i])){
vis.pb(i);
mark[i] = true;
}
}
for(auto u : vis){
FOR(i, 1, N) if(!mark[i] && check(pts[u], pts[i])){
mark[i] = true;
}
}
cout << sum_of(mark) << '\n';
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
file("task");
int T = 1;
// cin >> T;
FOR(i, 0, T) testcase(i);
return 0;
}
Compilation message (stderr)
relay.cpp: In function 'int main()':
relay.cpp:23:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen(task".inp", "r", stdin); \
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
relay.cpp:232:5: note: in expansion of macro 'file'
232 | file("task");
| ^~~~
relay.cpp:24:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen(task".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
relay.cpp:232:5: note: in expansion of macro 'file'
232 | file("task");
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |