Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- #define int long long
- #define mp make_pair
- #define pb push_back
- #pragma GCC optimize("O3")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC target("avx2")
- constexpr int N = (int)1e6+11;
- constexpr int INF = (int)1e18;
- constexpr int md = (int)998244353;
- constexpr int K = (int)60;
- void add(int& a,int b){
- a = (a+b >= md ? a+b-md : a+b);
- }
- void sub(int& a,int b){
- a = (a-b < 0 ? a-b+md : a-b);
- }
- mt19937 rnd(time(nullptr));
- struct pt {
- int x, y;
- pt(int x,int y):x(x),y(y){}
- };
- int orientation(pt a, pt b, pt c) {
- int v = (__int128)a.x*(b.y-c.y)+(__int128)b.x*(c.y-a.y)+(__int128)c.x*(a.y-b.y);
- if (v < 0) return -1; // clockwise
- if (v > 0) return +1; // counter-clockwise
- return 0;
- }
- bool cw(pt a, pt b, pt c, bool include_collinear) {
- int o = orientation(a, b, c);
- return o < 0 || (include_collinear && o == 0);
- }
- bool collinear(pt a, pt b, pt c) { return orientation(a, b, c) == 0; }
- void convex_hull(vector<pt>& a, bool include_collinear = false) {
- pt p0 = *min_element(a.begin(), a.end(), [](pt a, pt b) {
- return make_pair(a.y, a.x) < make_pair(b.y, b.x);
- });
- sort(a.begin(), a.end(), [&p0](const pt& a, const pt& b) {
- int o = orientation(p0, a, b);
- if (o == 0)
- return (__int128)(p0.x-a.x)*(p0.x-a.x) + (__int128)(p0.y-a.y)*(p0.y-a.y)
- < (__int128)(p0.x-b.x)*(p0.x-b.x) + (__int128)(p0.y-b.y)*(p0.y-b.y);
- return o < 0;
- });
- if (include_collinear) {
- int i = (int)a.size()-1;
- while (i >= 0 && collinear(p0, a[i], a.back())) i--;
- reverse(a.begin()+i+1, a.end());
- }
- vector<pt> st;
- for (int i = 0; i < (int)a.size(); i++) {
- while (st.size() > 1 && !cw(st[st.size()-2], st.back(), a[i], include_collinear))
- st.pop_back();
- st.push_back(a[i]);
- }
- a = st;
- }
- struct ConvexHull{
- vector<pt> points;
- ConvexHull(){}
- ConvexHull(vector<pt> v){
- points = v;
- convex_hull(points);
- }
- } A[20];
- ConvexHull Merge(ConvexHull A,ConvexHull B){
- vector<pt> v;
- for(auto& p : A.points)
- v.pb(p);
- for(auto& p : B.points)
- v.pb(p);
- ConvexHull C(v);
- return C;
- }
- void add(pt p){
- // A[0] = Merge(A[0],ConvexHull(vector<pt>{p}));
- // return;
- // for(int i = 0; i < 20; i++){
- // if(A[i].points.size() + 1 == (1 << (i+1))){
- // ConvexHull C = Merge(A[i],A[i+1]);
- // A[i+1] = C;
- // A[i] = ConvexHull();
- // } else {
- // A[i] = Merge(A[i],ConvexHull(vector<pt>{p}));
- // break;
- // }
- // }
- int id = rnd()%20;
- A[id] = Merge(A[id],vector<pt>{p});
- return;
- }
- int sg(int x){
- if(x == 0)
- return 1;
- if(x < 0)
- return 0;
- return 2;
- }
- bool check(int a,int b,int c){
- bool have[3] = {};
- for(int i = 0; i < 20; i++){
- for(auto& p : A[i].points){
- have[sg(a*p.x+b*p.y-c)] = 1;
- if(have[1])
- return false;
- if(have[0] + have[2] == 2)
- return false;
- }
- }
- return true;
- }
- void solve(){
- int n,q;
- cin >> n >> q;
- for(int i = 0; i < n; i++){
- int x,y;
- cin >> x >> y;
- add(pt(x,y));
- }
- for(int i = 0; i < q; i++){
- int tp;
- cin >> tp;
- if(tp == 1){
- int x,y;
- cin >> x >> y;
- add(pt(x,y));
- } else {
- int a,b,c;
- cin >> a >> b >> c;
- cout << (check(a,b,c) ? "YES" : "NO") << "\n";
- }
- }
- return;
- }
- signed main(){
- ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr);
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- int tests = 1;
- // cin >> tests;
- for(int test = 1; test <= tests; test++){
- solve();
- }
- return 0;
- }
- /**
- 2000
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement