Advertisement
welleyth

Orchad

Dec 7th, 2022
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. #define int long long
  9. #define mp make_pair
  10. #define pb push_back
  11.  
  12. #pragma GCC optimize("O3")
  13. #pragma GCC optimize("unroll-loops")
  14. #pragma GCC target("avx2")
  15.  
  16. constexpr int N = (int)1e6+11;
  17. constexpr int INF = (int)1e18;
  18. constexpr int md = (int)998244353;
  19. constexpr int K = (int)60;
  20.  
  21. void add(int& a,int b){
  22.     a = (a+b >= md ? a+b-md : a+b);
  23. }
  24. void sub(int& a,int b){
  25.     a = (a-b < 0 ? a-b+md : a-b);
  26. }
  27.  
  28. mt19937 rnd(time(nullptr));
  29.  
  30. struct pt {
  31.     int x, y;
  32.     pt(int x,int y):x(x),y(y){}
  33. };
  34.  
  35. int orientation(pt a, pt b, pt c) {
  36.     int v = (__int128)a.x*(b.y-c.y)+(__int128)b.x*(c.y-a.y)+(__int128)c.x*(a.y-b.y);
  37.     if (v < 0) return -1; // clockwise
  38.     if (v > 0) return +1; // counter-clockwise
  39.     return 0;
  40. }
  41.  
  42. bool cw(pt a, pt b, pt c, bool include_collinear) {
  43.     int o = orientation(a, b, c);
  44.     return o < 0 || (include_collinear && o == 0);
  45. }
  46. bool collinear(pt a, pt b, pt c) { return orientation(a, b, c) == 0; }
  47.  
  48. void convex_hull(vector<pt>& a, bool include_collinear = false) {
  49.     pt p0 = *min_element(a.begin(), a.end(), [](pt a, pt b) {
  50.         return make_pair(a.y, a.x) < make_pair(b.y, b.x);
  51.     });
  52.     sort(a.begin(), a.end(), [&p0](const pt& a, const pt& b) {
  53.         int o = orientation(p0, a, b);
  54.         if (o == 0)
  55.             return (__int128)(p0.x-a.x)*(p0.x-a.x) + (__int128)(p0.y-a.y)*(p0.y-a.y)
  56.                 < (__int128)(p0.x-b.x)*(p0.x-b.x) + (__int128)(p0.y-b.y)*(p0.y-b.y);
  57.         return o < 0;
  58.     });
  59.     if (include_collinear) {
  60.         int i = (int)a.size()-1;
  61.         while (i >= 0 && collinear(p0, a[i], a.back())) i--;
  62.         reverse(a.begin()+i+1, a.end());
  63.     }
  64.  
  65.     vector<pt> st;
  66.     for (int i = 0; i < (int)a.size(); i++) {
  67.         while (st.size() > 1 && !cw(st[st.size()-2], st.back(), a[i], include_collinear))
  68.             st.pop_back();
  69.         st.push_back(a[i]);
  70.     }
  71.  
  72.     a = st;
  73. }
  74.  
  75. struct ConvexHull{
  76.     vector<pt> points;
  77.     ConvexHull(){}
  78.     ConvexHull(vector<pt> v){
  79.         points = v;
  80.         convex_hull(points);
  81.     }
  82. } A[20];
  83.  
  84. ConvexHull Merge(ConvexHull A,ConvexHull B){
  85.     vector<pt> v;
  86.     for(auto& p : A.points)
  87.         v.pb(p);
  88.     for(auto& p : B.points)
  89.         v.pb(p);
  90.     ConvexHull C(v);
  91.     return C;
  92. }
  93.  
  94. void add(pt p){
  95. //    A[0] = Merge(A[0],ConvexHull(vector<pt>{p}));
  96. //    return;
  97. //    for(int i = 0; i < 20; i++){
  98. //        if(A[i].points.size() + 1 == (1 << (i+1))){
  99. //            ConvexHull C = Merge(A[i],A[i+1]);
  100. //            A[i+1] = C;
  101. //            A[i] = ConvexHull();
  102. //        } else {
  103. //            A[i] = Merge(A[i],ConvexHull(vector<pt>{p}));
  104. //            break;
  105. //        }
  106. //    }
  107.     int id = rnd()%20;
  108.     A[id] = Merge(A[id],vector<pt>{p});
  109.     return;
  110. }
  111.  
  112. int sg(int x){
  113.     if(x == 0)
  114.         return 1;
  115.     if(x < 0)
  116.         return 0;
  117.     return 2;
  118. }
  119.  
  120. bool check(int a,int b,int c){
  121.     bool have[3] = {};
  122.     for(int i = 0; i < 20; i++){
  123.         for(auto& p : A[i].points){
  124.             have[sg(a*p.x+b*p.y-c)] = 1;
  125.             if(have[1])
  126.                 return false;
  127.             if(have[0] + have[2] == 2)
  128.                 return false;
  129.         }
  130.     }
  131.     return true;
  132. }
  133.  
  134. void solve(){
  135.     int n,q;
  136.     cin >> n >> q;
  137.  
  138.     for(int i = 0; i < n; i++){
  139.         int x,y;
  140.         cin >> x >> y;
  141.         add(pt(x,y));
  142.     }
  143.  
  144.     for(int i = 0; i < q; i++){
  145.         int tp;
  146.         cin >> tp;
  147.         if(tp == 1){
  148.             int x,y;
  149.             cin >> x >> y;
  150.             add(pt(x,y));
  151.         } else {
  152.             int a,b,c;
  153.             cin >> a >> b >> c;
  154.             cout << (check(a,b,c) ? "YES" : "NO") << "\n";
  155.         }
  156.     }
  157.  
  158.     return;
  159. }
  160.  
  161. signed main(){
  162.     ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr);
  163. //    freopen("input.txt","r",stdin);
  164. //    freopen("output.txt","w",stdout);
  165.     int tests = 1;
  166. //    cin >> tests;
  167.     for(int test = 1; test <= tests; test++){
  168.         solve();
  169.     }
  170.     return 0;
  171. }
  172. /**
  173. 2000
  174.  
  175. **/
  176.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement