Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <algorithm>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <iomanip>
  6. #include <iostream>
  7. #include <sstream>
  8. #include <cmath>
  9. #include <set>
  10. #define fori(n) for (int i = 0; i < (int)n; i++)
  11. using namespace std;
  12.  
  13.  
  14.  
  15. struct node
  16. {
  17.     long long x, y, id;
  18. };
  19.  
  20.  
  21. int main()
  22. {
  23.     int n;
  24.     cin >> n;
  25.     vector<node> arr;
  26.     for (int i = 0; i < n; ++i)
  27.     {
  28.         int x, y;
  29.         cin >> x >> y;
  30.         node help, help2;
  31.         help.x = x; help.y = y; help.id = i;
  32.         help2.x = y; help2.y = x; help2.id = i;
  33.         arr.push_back(help);
  34.         if (x != y)
  35.             arr.push_back(help2);
  36.     }
  37.     sort(arr.begin(), arr.end(), [](const node& a, const node& b) -> bool
  38.     {
  39.         if (a.x > b.x)
  40.             return true;
  41.         if (a.x == b.x && a.y > b.y)
  42.             return true;
  43.         return false;
  44.     });
  45.     set<long long> maxs, ans;
  46.     maxs.insert(10000000000000);
  47.     for (int i = 0; i < arr.size(); ++i)
  48.     {
  49.         int m = -*maxs.begin();
  50.         if (arr[i].y >= m)
  51.         {
  52.             ans.insert(arr[i].id);
  53.         }
  54.         maxs.insert(-arr[i].y);
  55.     }
  56.     cout << ans.size();
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement