tiom4eg

openol H 100

Jan 16th, 2024
1,325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.55 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld long double
  9. //#define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define vi vector <int>
  12. #define mi vector <vector <int>>
  13. // Quick functions
  14. #define endl "\n"
  15. #define F first
  16. #define S second
  17. #define all(a) a.begin(), a.end()
  18. #define sz(a) (int)(a.size())
  19. #define pb push_back
  20. #define mp make_pair
  21. // Quick fors
  22. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  23. #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
  24. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  25. #define EACH(e, a) for (auto& e : a)
  26. // Pragmas
  27. #ifndef TIOM4EG
  28. #pragma GCC optimize("O3") // let the chaos begin!
  29. #pragma GCC target("avx,avx2,tune=native")
  30. #pragma GCC comment(linker, "/stack:200000000")
  31. #endif
  32. // PBDS
  33. #include <ext/pb_ds/assoc_container.hpp>
  34. #include <ext/pb_ds/tree_policy.hpp>
  35. #define pbds tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  36. using namespace __gnu_pbds;
  37. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  38. using namespace std;
  39. mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
  40. //#define int long long
  41. constexpr int INF = 1e9 + 7, MD = 998244353, MAX = 200007, LG = 19, R = 1 << LG, MOD = 1000000007, MOD2 = 1e9 + 9, B = 256;
  42. const ll INFLL = 1e18 + 7;
  43.  
  44.  
  45. struct IOPre {
  46.     static constexpr int TEN = 10, SZ = TEN * TEN * TEN * TEN;
  47.     std::array<char, 4 * SZ> num;
  48.     constexpr IOPre() : num{} {
  49.         for (int i = 0; i < SZ; i++) {
  50.             int n = i;
  51.             for (int j = 3; j >= 0; j--) {
  52.                 num[i * 4 + j] = static_cast<char>(n % TEN + '0');
  53.                 n /= TEN;
  54.             }
  55.         }
  56.     }
  57. };
  58. struct IO {
  59. #if !HAVE_DECL_FREAD_UNLOCKED
  60.     #define fread_unlocked fread
  61. #endif
  62. #if !HAVE_DECL_FWRITE_UNLOCKED
  63.     #define fwrite_unlocked fwrite
  64. #endif
  65.     static constexpr int SZ = 1 << 22, LEN = 32, TEN = 10, HUNDRED = TEN * TEN,
  66.                          THOUSAND = HUNDRED * TEN, TENTHOUSAND = THOUSAND * TEN,
  67.                          MAGIC_MULTIPLY = 205, MAGIC_SHIFT = 11, MASK = 15,
  68.                          TWELVE = 12, SIXTEEN = 16;
  69.     static constexpr IOPre io_pre = {};
  70.     std::array<char, SZ> input_buffer, output_buffer;
  71.     int input_ptr_left, input_ptr_right, output_ptr_right;
  72.  
  73.     IO()
  74.         : input_buffer{},
  75.           output_buffer{},
  76.           input_ptr_left{},
  77.           input_ptr_right{},
  78.           output_ptr_right{} {}
  79.     IO(const IO&) = delete;
  80.     IO(IO&&) = delete;
  81.     IO& operator=(const IO&) = delete;
  82.     IO& operator=(IO&&) = delete;
  83.  
  84.     ~IO() {
  85.         flush();
  86.     }
  87.  
  88.     template <class T>
  89.     struct is_char {
  90.         static constexpr bool value = std::is_same_v<T, char>;
  91.     };
  92.  
  93.     template <class T>
  94.     struct is_bool {
  95.         static constexpr bool value = std::is_same_v<T, bool>;
  96.     };
  97.  
  98.     template <class T>
  99.     struct is_string {
  100.         static constexpr bool value =
  101.             std::is_same_v<T, std::string> || std::is_same_v<T, const char*> ||
  102.             std::is_same_v<T, char*> || std::is_same_v<std::decay_t<T>, char*>;
  103.     };
  104.  
  105.     template <class T, class D = void>
  106.     struct is_custom {
  107.         static constexpr bool value = false;
  108.     };
  109.  
  110.     template <class T>
  111.     struct is_custom<T, std::void_t<typename T::internal_value_type>> {
  112.         static constexpr bool value = true;
  113.     };
  114.  
  115.     template <class T>
  116.     struct is_default {
  117.         static constexpr bool value = is_char<T>::value || is_bool<T>::value ||
  118.                                       is_string<T>::value ||
  119.                                       std::is_integral_v<T>;
  120.     };
  121.  
  122.     template <class T, class D = void>
  123.     struct is_iterable {
  124.         static constexpr bool value = false;
  125.     };
  126.  
  127.     template <class T>
  128.     struct is_iterable<
  129.         T, typename std::void_t<decltype(std::begin(std::declval<T>()))>> {
  130.         static constexpr bool value = true;
  131.     };
  132.  
  133.     template <class T, class D = void, class E = void>
  134.     struct is_applyable {
  135.         static constexpr bool value = false;
  136.     };
  137.  
  138.     template <class T>
  139.     struct is_applyable<T, std::void_t<typename std::tuple_size<T>::type>,
  140.                         std::void_t<decltype(std::get<0>(std::declval<T>()))>> {
  141.         static constexpr bool value = true;
  142.     };
  143.  
  144.     template <class T>
  145.     static constexpr bool needs_newline = (is_iterable<T>::value ||
  146.                                            is_applyable<T>::value) &&
  147.                                           (!is_default<T>::value);
  148.  
  149.     template <typename T, typename U>
  150.     struct any_needs_newline {
  151.         static constexpr bool value = false;
  152.     };
  153.     template <typename T>
  154.     struct any_needs_newline<T, std::index_sequence<>> {
  155.         static constexpr bool value = false;
  156.     };
  157.     template <typename T, std::size_t I, std::size_t... Is>
  158.     struct any_needs_newline<T, std::index_sequence<I, Is...>> {
  159.         static constexpr bool value =
  160.             needs_newline<decltype(std::get<I>(std::declval<T>()))> ||
  161.             any_needs_newline<T, std::index_sequence<Is...>>::value;
  162.     };
  163.  
  164.     inline void load() {
  165.         memmove(std::begin(input_buffer),
  166.                 std::begin(input_buffer) + input_ptr_left,
  167.                 input_ptr_right - input_ptr_left);
  168.         input_ptr_right =
  169.             input_ptr_right - input_ptr_left +
  170.             static_cast<int>(fread_unlocked(
  171.                 std::begin(input_buffer) + input_ptr_right - input_ptr_left, 1,
  172.                 SZ - input_ptr_right + input_ptr_left, stdin));
  173.         input_ptr_left = 0;
  174.     }
  175.  
  176.     inline void read_char(char& c) {
  177.         if (input_ptr_left + LEN > input_ptr_right) load();
  178.         c = input_buffer[input_ptr_left++];
  179.     }
  180.     inline void read_string(std::string& x) {
  181.         char c;
  182.         while (read_char(c), c < '!') continue;
  183.         x = c;
  184.         while (read_char(c), c >= '!') x += c;
  185.     }
  186.     template <class T>
  187.     inline std::enable_if_t<std::is_integral_v<T>, void> read_int(T& x) {
  188.         if (input_ptr_left + LEN > input_ptr_right) load();
  189.         char c = 0;
  190.         do c = input_buffer[input_ptr_left++];
  191.         while (c < '-');
  192.         [[maybe_unused]] bool minus = false;
  193.         if constexpr (std::is_signed<T>::value == true)
  194.             if (c == '-') minus = true, c = input_buffer[input_ptr_left++];
  195.         x = 0;
  196.         while (c >= '0')
  197.             x = x * TEN + (c & MASK), c = input_buffer[input_ptr_left++];
  198.         if constexpr (std::is_signed<T>::value == true)
  199.             if (minus) x = -x;
  200.     }
  201.  
  202.     inline void skip_space() {
  203.         if (input_ptr_left + LEN > input_ptr_right) load();
  204.         while (input_buffer[input_ptr_left] <= ' ') input_ptr_left++;
  205.     }
  206.  
  207.     inline void flush() {
  208.         fwrite_unlocked(std::begin(output_buffer), 1, output_ptr_right, stdout);
  209.         output_ptr_right = 0;
  210.     }
  211.  
  212.     inline void write_char(char c) {
  213.         if (output_ptr_right > SZ - LEN) flush();
  214.         output_buffer[output_ptr_right++] = c;
  215.     }
  216.  
  217.     inline void write_bool(bool b) {
  218.         if (output_ptr_right > SZ - LEN) flush();
  219.         output_buffer[output_ptr_right++] = b ? '1' : '0';
  220.     }
  221.  
  222.     inline void write_string(const std::string& s) {
  223.         for (auto x : s) write_char(x);
  224.     }
  225.  
  226.     inline void write_string(const char* s) {
  227.         while (*s) write_char(*s++);
  228.     }
  229.  
  230.     inline void write_string(char* s) {
  231.         while (*s) write_char(*s++);
  232.     }
  233.  
  234.     template <typename T>
  235.     inline std::enable_if_t<std::is_integral_v<T>, void> write_int(T x) {
  236.         if (output_ptr_right > SZ - LEN) flush();
  237.         if (!x) {
  238.             output_buffer[output_ptr_right++] = '0';
  239.             return;
  240.         }
  241.         if constexpr (std::is_signed<T>::value == true)
  242.             if (x < 0) output_buffer[output_ptr_right++] = '-', x = -x;
  243.         int i = TWELVE;
  244.         std::array<char, SIXTEEN> buf{};
  245.         while (x >= TENTHOUSAND) {
  246.             memcpy(std::begin(buf) + i,
  247.                    std::begin(io_pre.num) + (x % TENTHOUSAND) * 4, 4);
  248.             x /= TENTHOUSAND;
  249.             i -= 4;
  250.         }
  251.         if (x < HUNDRED) {
  252.             if (x < TEN) {
  253.                 output_buffer[output_ptr_right++] = static_cast<char>('0' + x);
  254.             } else {
  255.                 std::uint32_t q =
  256.                     (static_cast<std::uint32_t>(x) * MAGIC_MULTIPLY) >>
  257.                     MAGIC_SHIFT;
  258.                 std::uint32_t r = static_cast<std::uint32_t>(x) - q * TEN;
  259.                 output_buffer[output_ptr_right] = static_cast<char>('0' + q);
  260.                 output_buffer[output_ptr_right + 1] =
  261.                     static_cast<char>('0' + r);
  262.                 output_ptr_right += 2;
  263.             }
  264.         } else {
  265.             if (x < THOUSAND) {
  266.                 memcpy(std::begin(output_buffer) + output_ptr_right,
  267.                        std::begin(io_pre.num) + (x << 2) + 1, 3),
  268.                     output_ptr_right += 3;
  269.             } else {
  270.                 memcpy(std::begin(output_buffer) + output_ptr_right,
  271.                        std::begin(io_pre.num) + (x << 2), 4),
  272.                     output_ptr_right += 4;
  273.             }
  274.         }
  275.         memcpy(std::begin(output_buffer) + output_ptr_right,
  276.                std::begin(buf) + i + 4, TWELVE - i);
  277.         output_ptr_right += TWELVE - i;
  278.     }
  279.     template <typename T_>
  280.     IO& operator<<(T_&& x) {
  281.         using T = typename std::remove_cv<
  282.             typename std::remove_reference<T_>::type>::type;
  283.         static_assert(is_custom<T>::value or is_default<T>::value or
  284.                       is_iterable<T>::value or is_applyable<T>::value);
  285.         if constexpr (is_custom<T>::value) {
  286.             write_int(x.get());
  287.         } else if constexpr (is_default<T>::value) {
  288.             if constexpr (is_bool<T>::value) {
  289.                 write_bool(x);
  290.             } else if constexpr (is_string<T>::value) {
  291.                 write_string(x);
  292.             } else if constexpr (is_char<T>::value) {
  293.                 write_char(x);
  294.             } else if constexpr (std::is_integral_v<T>) {
  295.                 write_int(x);
  296.             }
  297.         } else if constexpr (is_iterable<T>::value) {
  298.             // strings are immune
  299.             using E = decltype(*std::begin(x));
  300.             constexpr char sep = needs_newline<E> ? '\n' : ' ';
  301.             int i = 0;
  302.             for (const auto& y : x) {
  303.                 if (i++) write_char(sep);
  304.                 operator<<(y);
  305.             }
  306.         } else if constexpr (is_applyable<T>::value) {
  307.             // strings are immune
  308.             constexpr char sep =
  309.                 (any_needs_newline<
  310.                     T, std::make_index_sequence<std::tuple_size_v<T>>>::value)
  311.                     ? '\n'
  312.                     : ' ';
  313.             int i = 0;
  314.             std::apply(
  315.                 [this, &sep, &i](auto const&... y) {
  316.                     (((i++ ? write_char(sep) : void()), this->operator<<(y)),
  317.                      ...);
  318.                 },
  319.                 x);
  320.         }
  321.         return *this;
  322.     }
  323.     template <typename T>
  324.     IO& operator>>(T& x) {
  325.         static_assert(is_custom<T>::value or is_default<T>::value or
  326.                       is_iterable<T>::value or is_applyable<T>::value);
  327.         static_assert(!is_bool<T>::value);
  328.         if constexpr (is_custom<T>::value) {
  329.             typename T::internal_value_type y;
  330.             read_int(y);
  331.             x = y;
  332.         } else if constexpr (is_default<T>::value) {
  333.             if constexpr (is_string<T>::value) {
  334.                 read_string(x);
  335.             } else if constexpr (is_char<T>::value) {
  336.                 read_char(x);
  337.             } else if constexpr (std::is_integral_v<T>) {
  338.                 read_int(x);
  339.             }
  340.         } else if constexpr (is_iterable<T>::value) {
  341.             for (auto& y : x) operator>>(y);
  342.         } else if constexpr (is_applyable<T>::value) {
  343.             std::apply([this](auto&... y) { ((this->operator>>(y)), ...); }, x);
  344.         }
  345.         return *this;
  346.     }
  347.  
  348.     IO* tie(std::nullptr_t) {
  349.         return this;
  350.     }
  351.     void sync_with_stdio(bool) {}
  352. };
  353. IO io;
  354. #define cin io
  355. #define cout io
  356.  
  357. #define int long long
  358.  
  359. const ld EPS = 1e-9, PI = 3.1415926535897;
  360.  
  361. int sign(int x) {
  362.     if (x > 0) return 1;
  363.     if (x < 0) return -1;
  364.     return 0;
  365. }
  366.  
  367. struct point {
  368.     int x, y;
  369.     point() : x(), y() {}
  370.     point(int x_, int y_) : x(x_), y(y_) {}
  371.     point operator-(point oth) const { return point(x - oth.x, y - oth.y); }
  372.     point operator+(point oth) const { return point(x + oth.x, y + oth.y); }
  373.     int operator*(point oth) const { return x * oth.x + y * oth.y; }
  374.     int operator%(point oth) const { return x * oth.y - y * oth.x; }
  375.     bool operator<(point oth) const {
  376.         if (sign(x - oth.x)) return x < oth.x;
  377.         if (sign(y - oth.y)) return y < oth.y;
  378.         return false;
  379.     }
  380.     bool operator==(const point& oth) const { return !sign(x - oth.x) && !sign(y - oth.y);  }
  381.     void print() { cout << '(' << x << ',' << y << ')'; }
  382. };
  383.  
  384. template <>
  385. struct std::hash <point> {
  386.     ll operator()(const point p) const { return ((ll)(p.x) << 32) | p.y; }
  387. };
  388.  
  389. bool half(point p) { return sign(p.y) < 0 || (!sign(p.y) && sign(p.x) < 0); }
  390. bool cmp(const point p1, const point p2) {
  391.     if (half(p1) != half(p2)) return half(p1) < half(p2);
  392.     if (p1 % p2) return sign(p1 % p2) > 0;
  393.     return p1 * p1 < p2 * p2;
  394. }
  395.  
  396. int n, m, q;
  397. // grundy
  398. bitset <10001> used;
  399. int cur, gf[10001];
  400. // geom
  401. point pts[10001];
  402. unordered_map <point, int> sec;
  403. // ds
  404. int cc, cnt[10001];
  405. set <pii> segs; // [l; r)
  406.  
  407. void add(const point p) {
  408.     int i;
  409.     if (sec.find(p) != sec.end()) i = sec[p];
  410.     else {
  411.         i = lower_bound(pts, pts + n, p, cmp) - pts;
  412.         if (i == n) i = 0;
  413.         sec[p] = i;
  414.     }
  415.     if (!cnt[i]++) {
  416.         auto it = segs.lower_bound({i, 0}), pit = segs.end();
  417.         bool fw = 0, bw = 0;
  418.         if (it != segs.end() && i + 1 == it->F) fw = 1;
  419.         if (it != segs.begin() && prev(it)->S == i) {
  420.             pit = prev(it);
  421.             bw = 1;
  422.         }
  423.         if (fw && bw) {
  424.             cur ^= gf[it->S - it->F];
  425.             cur ^= gf[pit->S - pit->F];
  426.             cur ^= gf[it->S - pit->F];
  427.             segs.insert({pit->F, it->S});
  428.             segs.erase(pit);
  429.             segs.erase(it);
  430.  
  431.         }
  432.         else if (fw) {
  433.             cur ^= gf[it->S - it->F];
  434.             cur ^= gf[it->S - it->F + 1];
  435.             segs.insert({i, it->S});
  436.             segs.erase(it);
  437.         }
  438.         else if (bw) {
  439.             cur ^= gf[pit->S - pit->F];
  440.             cur ^= gf[pit->S - pit->F + 1];
  441.             segs.insert({pit->F, i + 1});
  442.             segs.erase(pit);
  443.         }
  444.         else {
  445.             cur ^= gf[1];
  446.             segs.insert({i, i + 1});
  447.         }
  448.         cc++;
  449.     }
  450. }
  451.  
  452. void del(const point p) {
  453.     int i;
  454.     if (sec.find(p) != sec.end()) i = sec[p];
  455.     else {
  456.         i = lower_bound(pts, pts + n, p, cmp) - pts;
  457.         if (i == n) i = 0;
  458.         sec[p] = i;
  459.     }
  460.     if (!--cnt[i]) {
  461.         auto it = prev(segs.lower_bound({i + 1, 0}));
  462.         cur ^= gf[it->S - it->F];
  463.         if (it->F < i) {
  464.             cur ^= gf[i - it->F];
  465.             segs.insert({it->F, i});
  466.         }
  467.         if (i + 1 < it->S) {
  468.             cur ^= gf[it->S - (i + 1)];
  469.             segs.insert({i + 1, it->S});
  470.         }
  471.         segs.erase(it);
  472.         cc--;
  473.     }
  474. }
  475.  
  476. bool get() {
  477.     if (cc == n) return !gf[n - 2];
  478.     int w = cur;
  479.     if (cc && prev(segs.end())->S == n && segs.begin()->F == 0) {
  480.         int l1 = prev(segs.end())->S - prev(segs.end())->F, l2 = segs.begin()->S - segs.begin()->F;
  481.         w ^= gf[l1];
  482.         w ^= gf[l2];
  483.         w ^= gf[l1 + l2];
  484.     }
  485.     return !!w;
  486. }
  487.  
  488. signed main() {
  489.     gf[0] = 0, gf[1] = 1;
  490.     FOR(i, 2, 10001) {
  491.         used.set();
  492.         used.reset(gf[i - 1]);
  493.         FOR(j, 0, i / 2) used.reset(gf[j] ^ gf[i - 2 - j]);
  494.         gf[i] = used._Find_first();
  495.     }
  496.     fastIO;
  497.     cin >> n >> m >> q;
  498.     point o; cin >> o.x >> o.y;
  499.     FOR(i, 0, n) cin >> pts[i].x >> pts[i].y, pts[i] = pts[i] - o;
  500.     sort(pts, pts + n, cmp);
  501.     FOR(i, 0, m) {
  502.         point p; cin >> p.x >> p.y;
  503.         add(p - o);
  504.     }
  505.     cout << (get() ? "Alice\n" : "Bob\n");
  506.     while (q--) {
  507.         char op; point p; cin >> op >> p.x >> p.y;
  508.         if (op == '+') add(p - o);
  509.         else del(p - o);
  510.         cout << (get() ? "Alice\n" : "Bob\n");
  511.     }
  512. }
  513.  
Advertisement
Add Comment
Please, Sign In to add comment