This documentation is automatically generated by online-judge-tools/verification-helper
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/3/CGL_3_C"
#include "../../Src/Template/IOSetting.hpp"
#include "../../Src/GeometryR2/Point.hpp"
#include "../../Src/GeometryR2/Polygon.hpp"
#include "../../Src/GeometryR2/Contain/PolygonContainsPoint.hpp"
int main() {
using namespace zawa;
using namespace geometryR2;
SetFastIO();
int n; std::cin >> n;
Polygon ps(n);
std::cin >> ps;
int q; std::cin >> q;
for (int _{} ; _ < q ; _++) {
Point p; std::cin >> p;
auto ans{PolygonContainsPoint(ps, p)};
std::cout << (ans == INSIDE ? 2 : (ans == ONLINE ? 1 : 0)) << '\n';
}
}
#line 1 "Test/AOJ/CGL_3_C.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/3/CGL_3_C"
#line 2 "Src/Template/IOSetting.hpp"
#line 2 "Src/Template/TypeAlias.hpp"
#include <cstdint>
#include <cstddef>
namespace zawa {
using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;
using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using usize = std::size_t;
} // namespace zawa
#line 4 "Src/Template/IOSetting.hpp"
#include <iostream>
#include <iomanip>
namespace zawa {
void SetFastIO() {
std::cin.tie(nullptr)->sync_with_stdio(false);
}
void SetPrecision(u32 dig) {
std::cout << std::fixed << std::setprecision(dig);
}
} // namespace zawa
#line 2 "Src/GeometryR2/Point.hpp"
#line 2 "Src/GeometryR2/Real.hpp"
#line 4 "Src/GeometryR2/Real.hpp"
#include <cmath>
#include <cassert>
namespace zawa {
namespace geometryR2 {
using Real = long double;
namespace internal {
Real EPS{1e-12};
constexpr i32 negative{-1};
constexpr i32 zero{};
constexpr i32 positive{1};
} // namespace internal
Real& Eps() {
return internal::EPS;
}
i32 Sign(Real value) {
if (value < -Eps()) return internal::negative;
if (value > Eps()) return internal::positive;
return internal::zero;
}
bool Zero(Real value) {
return Sign(value) == internal::zero;
}
bool Positive(Real value) {
return Sign(value) == internal::positive;
}
bool Negative(Real value) {
return Sign(value) == internal::negative;
}
bool Equal(Real a, Real b) {
return Zero(a - b);
}
bool Smaller(Real a, Real b) {
return Negative(a - b);
}
bool Bigger(Real a, Real b) {
return Positive(a - b);
}
Real Square(Real value) {
return (Zero(value) ? value : value * value);
}
Real Sqrt(Real value) {
assert(!Negative(value));
return (Zero(value) ? value : sqrtl(value));
}
Real Abs(Real value) {
return (Negative(value) ? -value : value);
}
} // namespace geometryR2
} // namespace zawa
#line 2 "Src/GeometryR2/Angle.hpp"
#line 4 "Src/GeometryR2/Angle.hpp"
#line 6 "Src/GeometryR2/Angle.hpp"
namespace zawa {
namespace geometryR2 {
constexpr Real PI{acosl(-1)};
constexpr Real TAU{static_cast<Real>(2) * PI};
constexpr Real ArcToRadian(Real arc) {
return (arc * PI) / static_cast<Real>(180);
}
constexpr Real RadianToArc(Real radian) {
return (radian * static_cast<Real>(180)) / PI;
}
} // namespace geometryR2
} // namespace zawa
#line 5 "Src/GeometryR2/Point.hpp"
#line 9 "Src/GeometryR2/Point.hpp"
namespace zawa {
namespace geometryR2 {
class Point {
private:
Real x_{}, y_{};
public:
/* constructor */
Point() = default;
Point(Real x, Real y) : x_{x}, y_{y} {}
/* getter, setter */
Real x() const {
return x_;
}
Real& x() {
return x_;
}
Real y() const {
return y_;
}
Real& y() {
return y_;
}
/* operator */
Point& operator+=(const Point& rhs) {
x_ += rhs.x();
y_ += rhs.y();
return *this;
}
friend Point operator+(const Point& lhs, const Point& rhs) {
return Point{lhs} += rhs;
}
Point operator+() const {
return *this;
}
Point& operator-=(const Point& rhs) {
x_ -= rhs.x();
y_ -= rhs.y();
return *this;
}
friend Point operator-(const Point& lhs, const Point& rhs) {
return Point{lhs} -= rhs;
}
Point operator-() const {
return Point{} - *this;
}
Point& operator*=(Real k) {
x_ *= k;
y_ *= k;
return *this;
}
friend Point operator*(Real k, const Point& p) {
return Point{p} *= k;
}
friend Point operator*(const Point& p, Real k) {
return Point{p} *= k;
}
Point& operator/=(Real k) {
assert(!Zero(k));
x_ /= k;
y_ /= k;
return *this;
}
friend Point operator/(Real k, const Point& p) {
return Point{p} /= k;
}
friend Point operator/(const Point& p, Real k) {
return Point{p} /= k;
}
friend bool operator==(const Point& lhs, const Point& rhs) {
return Equal(lhs.x(), rhs.x()) and Equal(lhs.y(), rhs.y());
}
friend bool operator!=(const Point& lhs, const Point& rhs) {
return !Equal(lhs.x(), rhs.x()) or !Equal(lhs.y(), rhs.y());
}
friend bool operator<(const Point& lhs, const Point& rhs) {
return Smaller(lhs.x(), rhs.x()) or
(Equal(lhs.x(), rhs.x()) and Smaller(lhs.y(), rhs.y()));
}
friend bool operator<=(const Point& lhs, const Point& rhs) {
return Smaller(lhs.x(), rhs.x()) or
(Equal(lhs.x(), rhs.x()) and (Smaller(lhs.y(), rhs.y()) or Equal(lhs.y(), rhs.y())));
}
friend bool operator>(const Point& lhs, const Point& rhs) {
return Bigger(lhs.x(), rhs.x()) or
(Equal(lhs.x(), rhs.x()) and Bigger(lhs.y(), rhs.y()));
}
friend bool operator>=(const Point& lhs, const Point& rhs) {
return Bigger(lhs.x(), rhs.x()) or
(Equal(lhs.x(), rhs.x()) and (Bigger(lhs.y(), rhs.y()) or Equal(lhs.y(), rhs.y())));
}
friend std::istream& operator>>(std::istream& is, Point& p) {
is >> p.x_ >> p.y_;
return is;
}
friend std::ostream& operator<<(std::ostream& os, const Point& p) {
os << '(' << p.x_ << ',' << p.y_ << ')';
return os;
}
/* member function */
Real normSquare() const {
return Square(x_) + Square(y_);
}
Real norm() const {
return Sqrt(normSquare());
}
void normalize() {
assert((*this) != Point{});
(*this) /= norm();
}
Point normalized() const {
Point res{*this};
res.normalize();
return res;
}
Point rotated(Real radian) const {
return Point{
x_ * cosl(radian) - y_ * sinl(radian),
x_ * sinl(radian) + y_ * cosl(radian)
};
}
void rotate(Real radian) {
*this = rotated(radian);
}
Point rotatedByArc(Real arc) const {
return rotated(ArcToRadian(arc));
}
void rotateByArc(Real arc) {
*this = rotatedByArc(arc);
}
Real argument() const {
return (Negative(y_) ? TAU : static_cast<Real>(0)) + atan2l(y_, x_);
}
Real argumentByArc() const {
return RadianToArc(argument());
}
/* friend function */
friend Real Dot(const Point& lhs, const Point& rhs) {
return lhs.x() * rhs.x() + lhs.y() * rhs.y();
}
friend Real Cross(const Point& lhs, const Point& rhs) {
return lhs.x() * rhs.y() - lhs.y() * rhs.x();
}
friend Real Argument(const Point& lhs, const Point& rhs) {
return rhs.argument() - lhs.argument();
}
friend bool ArgComp(const Point& lhs, const Point& rhs) {
return Smaller(lhs.argument(), rhs.argument());
}
};
using Vector = Point;
} // namespace geometryR2
} // namespace zawa
#line 2 "Src/GeometryR2/Polygon.hpp"
#line 2 "Src/GeometryR2/Relation.hpp"
#line 5 "Src/GeometryR2/Relation.hpp"
namespace zawa {
namespace geometryR2 {
enum RELATION {
// p0 -> p1 -> p2の順で直線上に並んでいる
ONLINE_FRONT = -2,
// (p1 - p0) -> (p2 - p0)が時計回りになっている
CLOCKWISE,
// p0 -> p2 -> p1の順で直線上に並んでいる
ON_SEGMENT,
// (p1 - p0) -> (p2 - p0)が反時計回りになっている
COUNTER_CLOCKWISE,
// p2 -> p0 -> p1、またはp1 -> p0 -> p2の順で直線上に並んでいる
ONLINE_BACK
};
RELATION Relation(const Point& p0, const Point& p1, const Point& p2) {
Point a{p1 - p0}, b{p2 - p0};
if (Positive(Cross(a, b))) return COUNTER_CLOCKWISE;
if (Negative(Cross(a, b))) return CLOCKWISE;
if (Negative(Dot(a, b))) return ONLINE_BACK;
if (Smaller(a.normSquare(), b.normSquare())) return ONLINE_FRONT;
return ON_SEGMENT;
};
} // namespace geometryR2
} // namespace zawa
#line 7 "Src/GeometryR2/Polygon.hpp"
#include <algorithm>
#line 10 "Src/GeometryR2/Polygon.hpp"
#include <vector>
namespace zawa {
namespace geometryR2 {
class Polygon {
private:
std::vector<Point> data_;
public:
/* member */
usize size() const {
return data_.size();
}
/* constructor */
Polygon() = default;
Polygon(const Polygon& polygon) : data_{polygon.data_} {}
Polygon(const std::vector<Point>& data) : data_{data} {}
Polygon(usize n) : data_{n} {
assert(n >= static_cast<usize>(3));
}
/* operator[] */
Point& operator[](usize i) {
assert(i < size());
return data_[i];
}
const Point& operator[](usize i) const {
assert(i < size());
return data_[i];
}
Polygon& operator=(const Polygon& polygon) {
data_ = polygon.data_;
return *this;
}
friend std::istream& operator>>(std::istream& is, Polygon& polygon) {
for (size_t i{} ; i < polygon.size() ; i++) {
is >> polygon[i];
}
return is;
}
friend std::ostream& operator<<(std::ostream& os, const Polygon& polygon) {
for (usize i{} ; i < polygon.size() ; i++) {
std::cout << polygon[i] << (i + 1 == polygon.size() ? "" : " ");
}
return os;
}
/* member function */
void orderRotate(usize i) {
assert(i < size());
std::rotate(data_.begin(), data_.begin() + i, data_.end());
}
void normalForm() {
auto index{std::distance(data_.begin(), std::min_element(data_.begin(), data_.end()))};
orderRotate(index);
}
Polygon normalFormed() const {
Polygon res{*this};
res.normalForm();
return res;
}
bool isConvex() const {
assert(size() >= static_cast<usize>(3));
for (usize i{} ; i < size() ; i++) {
if (Relation(data_[i], data_[i+1==size()?0:i+1], data_[i+2>=size()?i+2-size():i+2])
== CLOCKWISE) {
return false;
}
}
return true;
}
Real area() const {
assert(size() >= static_cast<usize>(3));
Real res{};
for (usize i{1} ; i < size() ; i++) {
res += Cross(data_[i] - data_[0], data_[i+1==size()?0:i+1] - data_[0]);
}
return res / static_cast<Real>(2);
}
void pushBack(const Point& p) {
data_.push_back(p);
}
void emplaceBack(Real x, Real y) {
data_.emplace_back(x, y);
}
};
} // namespace geometryR2
} // namespace zawa
#line 2 "Src/GeometryR2/Contain/PolygonContainsPoint.hpp"
#line 2 "Src/GeometryR2/Contain/State.hpp"
namespace zawa {
namespace geometryR2 {
enum ContainState {
INSIDE,
ONLINE,
OUTSIDE
};
} // namespace geometryR2
} // namespace zawa
#line 9 "Src/GeometryR2/Contain/PolygonContainsPoint.hpp"
#line 11 "Src/GeometryR2/Contain/PolygonContainsPoint.hpp"
#include <utility>
namespace zawa {
namespace geometryR2 {
ContainState PolygonContainsPoint(const Polygon& polygon, const Point& p) {
usize n{polygon.size()};
assert(n >= static_cast<usize>(3));
bool odd{};
for (usize i{} ; i < n ; i++) {
if (polygon[i] == p) {
return ONLINE;
}
if (Relation(polygon[i], polygon[i+1==n?0:i+1], p) == ON_SEGMENT) {
return ONLINE;
}
Vector a{polygon[i] - p}, b{polygon[i+1==n?0:i+1] - p};
if (Bigger(a.y(), b.y())) std::swap(a, b);
odd ^= !Positive(a.y()) and Positive(b.y()) and Positive(Cross(a, b));
}
return (odd ? INSIDE : OUTSIDE);
}
} // namespace geometryR2
} // namespace zawa
#line 7 "Test/AOJ/CGL_3_C.test.cpp"
int main() {
using namespace zawa;
using namespace geometryR2;
SetFastIO();
int n; std::cin >> n;
Polygon ps(n);
std::cin >> ps;
int q; std::cin >> q;
for (int _{} ; _ < q ; _++) {
Point p; std::cin >> p;
auto ans{PolygonContainsPoint(ps, p)};
std::cout << (ans == INSIDE ? 2 : (ans == ONLINE ? 1 : 0)) << '\n';
}
}