提交时间:2024-03-02 10:25:15

运行 ID: 133894

#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 005; struct Node{ int x, y; bool operator < (const Node &o) const { if (y != o.y) return y < o.y; return x < o.x; } }; int main() { int x; cin >> x; for (int adf = 1; adf <= x; adf++) { static Node a[N]; int n, ans = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; sort(a + 1, a + n + 1); int cur = a[1].y; for (int i = 1; i < n; i++) { ans++; if (cur < a[i + 1].x) cur = a[i + 1].y, ans++; } cout << ans << endl; } }