#include #include #include int C = 1; std::pair P[1000010]; int check[1000010]; int next[1000010],prev[1000010]; std::vector< std::pair > temp; int main() { int a,b,c; scanf("%d%d%d",&a,&b,&c); for(int i=1;i<=c;i++) scanf("%d%d",&P[i].first,&P[i].second); std::sort(P+1,P+c+1); for(int i=1;i<=c;i++) { if(P[i].first!=P[i-1].first) prev[i] = i; else prev[i] = prev[i-1]; } for(int i=c;i>=1;i--) { if(P[i].first!=P[i+1].first) next[i] = i; else next[i] = next[i+1]; } for(int i=1;i<=c;i++) { if(i==next[i]) { for(int j=prev[i];j<=i;j++) { int min = 1, max = C-1; int p = 0; while(min<=max) { int h = (min+max)/2; if(check[h] t = temp.back(); temp.pop_back(); if(t.first==C) C++, check[t.first] = t.second; else check[t.first] = check[t.first]