#include #include using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i=0;i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} template struct segment_tree { using T = typename M::T; public: explicit segment_tree() {} explicit segment_tree(int N) : segment_tree(std::vector(N, M::e())) {} explicit segment_tree(const std::vector& v) { int N = (int)v.size(); n = N; size = 1; while (size < N) size <<= 1; data.resize(2 * size, M::e()); for (int i = 0; i < N; i++) data[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) update(i); }; void set(int p, T x) { assert(0 <= p && p < n); p += size; data[p] = x; while (p > 1) { p >>= 1; update(p); } } T get(int p) { assert(0 <= p && p < n); p += size; return data[p]; } T prod(int l, int r) { assert(0 <= l && l <= r && r <= n); T vl = M::e(), vr = M::e(); l += size; r += size; while (l < r) { if (l & 1) vl = M::op(vl, data[l++]); if (r & 1) vr = M::op(data[--r], vr); l >>= 1; r >>= 1; } return M::op(vl, vr); } T all_prod() { return data[1]; } private: int n, size; std::vector data; void update(int p) { data[p] = M::op(data[2 * p], data[2 * p + 1]); } }; const ll INF=1LL<<60; struct Monoid{ using T=ll; static T op(T l,T r){return min(l,r);} static T e(){return INF;} }; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll H,W; int N; cin>>H>>W>>N; vectorA(N),B(N); unordered_map>V; unordered_mapmp; vectorI; for(int i=0;i>A[i]>>B[i]; A[i]--; B[i]--; V[B[i]].push_back(A[i]); I.push_back(B[i]); } sort(all(I)); I.erase(unique(all(I)),I.end()); int L=I.size(); for(int i=0;iseg1(L),seg2(L); for(int i=0;i