Dang_Quan_10_Tin

New

Jul 17th, 2020 (edited)
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5. using ld = long double;
  6. using ull = unsigned long long;
  7.  
  8. template <class T>
  9. void read(T &x)
  10. {
  11.     x = 0;
  12.     register int c;
  13.     while ((c = getchar()) && (c > '9' || c < '0'))
  14.         ;
  15.     for (; c >= '0' && c <= '9'; c = getchar())
  16.         x = x * 10 + c - '0';
  17. }
  18.  
  19. constexpr bool typetest = 0;
  20. constexpr int N = 3e4 + 5;
  21. constexpr int Inf = 1e9 + 7;
  22.  
  23. struct SegmentTree
  24. {
  25.     int n;
  26.     int st[N * 4], lazy[N * 4];
  27.  
  28.     SegmentTree()
  29.     {
  30.         memset(st, 0, sizeof st);
  31.         memset(lazy, 0, sizeof lazy);
  32.     }
  33.  
  34.     void Update(int id, int l, int r, const int &a, const int &b, const int &v)
  35.     {
  36.         if (l > b || r < a)
  37.             return;
  38.  
  39.         if (l >= a && r <= b)
  40.         {
  41.             lazy[id] += v;
  42.             return;
  43.         }
  44.  
  45.         Update(id << 1, l, (l + r) / 2, a, b, v);
  46.         Update(id << 1 | 1, (l + r) / 2 + 1, r, a, b, v);
  47.  
  48.         st[id] = (lazy[id << 1] ? ((l + r) / 2 - l + 1) : st[id << 1]) + (lazy[id << 1 | 1] ? (r - (l + r) / 2) : st[id << 1 | 1]);
  49.     }
  50.  
  51.     void Update(int l, int r, int v)
  52.     {
  53.         Update(1, 1, n, l + 1, r + 1, v);
  54.     }
  55. } f;
  56.  
  57. int n;
  58. int x[N], y[N], z[N], t[N];
  59. vector<pair<int, int>> in[N], out[N];
  60.  
  61. void Read()
  62. {
  63.     cin >> n;
  64.     for (int i = 1; i <= n; ++i)
  65.     {
  66.         cin >> x[i] >> y[i] >> z[i] >> t[i];
  67.         in[x[i]].emplace_back(y[i], t[i] - 1);
  68.         out[z[i]].emplace_back(y[i], t[i] - 1);
  69.     }
  70. }
  71.  
  72. void Solve()
  73. {
  74.     f.n = 3e4;
  75.  
  76.     ll ans(0);
  77.  
  78.     for (int i = 0; i < 3e4; ++i)
  79.     {
  80.         for (auto j : in[i])
  81.             f.Update(j.first, j.second, 1);
  82.         for (auto j : out[i])
  83.             f.Update(j.first, j.second, -1);
  84.  
  85.         ans += (f.lazy[1] ? f.n : f.st[1]);
  86.     }
  87.  
  88.     cout << ans;
  89. }
  90.  
  91. int32_t main()
  92. {
  93.     ios::sync_with_stdio(0);
  94.     cin.tie(0);
  95.     cout.tie(0);
  96.     int t(1);
  97.     if (typetest)
  98.         cin >> t;
  99.     for (int _ = 1; _ <= t; ++_)
  100.     {
  101.         //cout << "Case #" << _ << ": ";
  102.         Read();
  103.         Solve();
  104.     }
  105.     //cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  106. }
Add Comment
Please, Sign In to add comment