#include #include #define fi first #define se second using namespace std; using namespace atcoder; using P = pair; int op(int x, int y) { return max(x, y);} int e() { return -1;} int main(){ int N, M, Q; cin >> N >> M >> Q; vector

AB; for(int i=0; i> a >> b; AB.emplace_back(make_pair(a, b)); } sort(AB.begin(), AB.end(), [](auto x, auto y){ if(x.fi < y.fi) return true; if(x.fi > y.fi) return false; return x.se > y.se; }); segtree seg(max(N, M) + 1); vector dp(max(N, M) + 1, -1); dp[0] = 0; seg.set(0, 0); for(auto& p: AB){ int a, b; tie(a, b) = p; int x = seg.prod(0, b) + 1; dp[b] = x; seg.set(b, x); } int ANS = seg.all_prod(); cout << ANS << endl; return 0; }