EntropyIncreaser

HDU 6759

Jul 21st, 2020
1,365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <cctype>
  7.  
  8. #include <algorithm>
  9. #include <random>
  10. #include <bitset>
  11. #include <queue>
  12. #include <functional>
  13. #include <set>
  14. #include <map>
  15. #include <vector>
  16. #include <chrono>
  17. #include <iostream>
  18. #include <limits>
  19. #include <numeric>
  20.  
  21. #define LOG(FMT...) fprintf(stderr, FMT)
  22.  
  23. using namespace std;
  24.  
  25. typedef long long ll;
  26. typedef unsigned long long ull;
  27.  
  28. // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  29.  
  30. template<class T>
  31. istream &operator>>(istream &is, vector<T> &v) {
  32.   for (T &x : v)
  33.     is >> x;
  34.   return is;
  35. }
  36.  
  37. template<class T>
  38. ostream &operator<<(ostream &os, const vector<T> &v) {
  39.   if (!v.empty()) {
  40.     os << v.front();
  41.     for (int i = 1; i < v.size(); ++i)
  42.       os << ' ' << v[i];
  43.   }
  44.   return os;
  45. }
  46.  
  47. typedef pair<ll, ll> pii;
  48.  
  49. #define x first
  50. #define y second
  51.  
  52. pii operator+(const pii &lhs, const pii &rhs) { return pii(lhs.x + rhs.x, lhs.y + rhs.y); }
  53.  
  54. pii operator-(const pii &lhs, const pii &rhs) { return pii(lhs.x - rhs.x, lhs.y - rhs.y); }
  55.  
  56. ll operator^(const pii &lhs, const pii &rhs) { return lhs.x * rhs.x + lhs.y * rhs.y; }
  57.  
  58. ll operator*(const pii &lhs, const pii &rhs) { return lhs.x * rhs.y - lhs.y * rhs.x; }
  59.  
  60. int main() {
  61. #ifdef ELEGIA
  62.   freopen("test.in", "r", stdin);
  63.   int nol_cl = clock();
  64. #endif
  65.   ios::sync_with_stdio(false);
  66.   cin.tie(nullptr);
  67.  
  68.   int T;
  69.   cin >> T;
  70.   while (T--) {
  71.     int n;
  72.     cin >> n;
  73.     vector<pii> t(n);
  74.     for (int i = 0; i < n; ++i)
  75.       cin >> t[i].x >> t[i].y;
  76.     sort(t.begin(), t.end());
  77.     vector<pii> stk;
  78.     vector<int> vs;
  79.     for (int i = 0; i < n; ++i) {
  80.       if (!stk.empty() && stk.back() == t[i]) {
  81.         vs.back() = 0;
  82.         continue;
  83.       }
  84.       while (!stk.empty() && stk.back().x == t[i].x) {
  85.         stk.pop_back();
  86.         vs.pop_back();
  87.       }
  88.       while (stk.size() >= 2 && ((stk.back() - stk[stk.size() - 2]) * (t[i] - stk.back())) >= 0) {
  89.         stk.pop_back();
  90.         vs.pop_back();
  91.       }
  92.       stk.push_back(t[i]);
  93.       vs.push_back(1);
  94.     }
  95.     int i = 0;
  96.     int ans = 0;
  97.     while (i + 1 < stk.size() && stk[i + 1].y >= stk[i].y) ++i;
  98.     for (int j = i; j < stk.size(); ++j) ans += vs[j];
  99.     //for (int j = i; j < stk.size(); ++j) cerr << "TAKE " << stk[j].x << ' ' << stk[j].y << '\n';
  100.     cout << ans << '\n';
  101.   }
  102.  
  103. #ifdef ELEGIA
  104.   LOG("Time: %dms\n", int ((clock()
  105.           -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
  106. #endif
  107.   return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment