Advertisement
ivnikkk

Untitled

Apr 28th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <cmath>
  7. #include <iomanip>
  8. #include <algorithm>
  9. #include <map>
  10. #include <set>
  11. #include <deque>
  12. #include <unordered_map>
  13. #include <stack>
  14. #include <queue>
  15. #include <random>
  16.  
  17. #define ll long long
  18. #define ld long double
  19. #define mp make_pair
  20. #define all(v) (v).begin(), (v).end()
  21.  
  22. using namespace std;
  23.  
  24. const ll inf = 1e18, siz = 2097152; // 2097152
  25.  
  26. class node {
  27. public:
  28.     node() = default;
  29.    
  30.     ll sum, d;
  31.    
  32.     node(const ll& sum, const ll& d) {
  33.         this->sum = sum;
  34.         this->d = d;
  35.     }
  36. };
  37.  
  38. vector<node> t(siz * 2 - 1, node(0, 0));
  39.  
  40. void run() {
  41.     ll n;
  42.     cin >> n;
  43.    
  44.     t = vector<node>(siz * 2 - 1, node(0, 0));
  45.     vector<pair<pair<ll, ll>, pair<ll, ll>>> point;
  46.     for (ll i = 0; i < n; i++) {
  47.         ll x1, y1, x2, y2;
  48.         cin >> x1 >> y1 >> x2 >> y2;
  49.         x1 += 1e6;
  50.         x2 += 1e6;
  51.         y1 += 1e6;
  52.         y2 += 1e6;
  53.  
  54.         pair<pair<ll, ll>, pair<ll, ll>> p1(mp(mp(x1, 1), mp(y1, y2)));
  55.         pair<pair<ll, ll>, pair<ll, ll>> p2(mp(mp(x2, -1), mp(y1, y2)));
  56.  
  57.         point.push_back(p1);
  58.         point.push_back(p2);
  59.     }
  60.  
  61.     sort(all(point));
  62.  
  63.     for (ll i = 0; i < 2 * n; i++) {
  64.         if (point[i].first.second == 1) {
  65.             sum += t[0].sum;
  66.             upd(0, 0, siz, point[i].second.first, point[i].second.second + 1, 1);
  67.         }
  68.         else {
  69.             sum += t[0].sum;
  70.             upd(0, 0, siz, point[i].second.first, point[i].second.second + 1,   -1);
  71.         }
  72.     }
  73. }
  74.  
  75. int main() {
  76.     ios::sync_with_stdio(false);
  77.     cin.tie(nullptr);
  78.  
  79.     ll t = 1;
  80.     //cin >> t;
  81.     while (t--) {
  82.         run();
  83.         cout << "\n";
  84.     }
  85.  
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement