Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <iomanip>
- #include <iostream>
- #include <sstream>
- #include <cmath>
- #include <set>
- #define fori(n) for (int i = 0; i < (int)n; i++)
- using namespace std;
- struct node
- {
- long long x, y, id;
- };
- int main()
- {
- int n;
- cin >> n;
- vector<node> arr;
- for (int i = 0; i < n; ++i)
- {
- int x, y;
- cin >> x >> y;
- node help, help2;
- help.x = x; help.y = y; help.id = i;
- help2.x = y; help2.y = x; help2.id = i;
- arr.push_back(help);
- if (x != y)
- arr.push_back(help2);
- }
- sort(arr.begin(), arr.end(), [](const node& a, const node& b) -> bool
- {
- if (a.x > b.x)
- return true;
- if (a.x == b.x && a.y > b.y)
- return true;
- return false;
- });
- set<long long> maxs, ans;
- maxs.insert(10000000000000);
- for (int i = 0; i < arr.size(); ++i)
- {
- int m = -*maxs.begin();
- if (arr[i].y >= m)
- {
- ans.insert(arr[i].id);
- }
- maxs.insert(-arr[i].y);
- }
- cout << ans.size();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement