#include #define mp make_pair #define pb push_back using namespace std; using ll = long long int; template ostream& operator+(ostream& out, const vector &vec){ for(const auto &x : vec){ out< ostream& operator*(ostream& out, const vector &vec){ for(const auto &x : vec){ out+x; } return out; } template istream& operator>>(istream& in, vector &vec){ for(auto &x : vec){ in>>x; } return in; } void solve(){ int n; cin>>n; vector> a(n); vector vals; for(auto &[r, R] : a){ cin>>r>>R; vals.push_back(r); vals.push_back(R); } sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); for(auto &[r, R] : a){ r = lower_bound(vals.begin(), vals.end(), r) - vals.begin() + 1; R = lower_bound(vals.begin(), vals.end(), R) - vals.begin() + 1; } vector dp(vals.size() + 1); sort(a.begin(), a.end(), [](const array &a, const array &b){ return a[1] < b[1]; }); for(int i=1,j=0;i<=vals.size();i++){ dp[i] = dp[i-1]; while(j < n && a[j][1] == i){ dp[i] = max(dp[i], dp[a[j][0]] + 1); ++j; } } cout<