提交时间:2024-04-05 16:42:46

运行 ID: 141516

# include <bits/stdc++.h> using namespace std ; int f [100010] , n , m , p ; struct node { int x , y ; bool operator < ( const node &b ) const { return x != b . x ? x < b . x : y < b . y ; } void rd ( ) { cin >> x >> y ; } } t [100010] ; int HalfFind ( node num , int l , int r ) { while ( l <= r ) { int mid = ( l + r ) >> 1 ; if ( t [f [mid]] . y > num . y ) { l = mid + 1 ; } else { r = mid - 1 ; } } return l - 1 ; } int main() { cin >> n >> m >> p ; for ( int i = 1 ; i <= p ; i ++ ) { t [i] . rd ( ) ; } f [1] = 1 ; int lgg = 1 ; sort ( t + 1 , t + 1 + p ) ; for ( int i = 2 ; i <= p ; i ++ ) { if ( t [i] . y < t [f [lgg]] . y ) { f [++ lgg] = i ; } else { int pos = HalfFind ( t [i] , 1 , lgg ) ; f [pos + 1] = i ; } } cout << lgg << endl ; return 0; }