constint maxn = 1000010; bool vis[maxn]; int a[maxn], x[maxn], ans[maxn]; vector<int> eq[maxn], mr[maxn]; structnode { int v, id; voidSet(int x){ id = x; v = a[id]; } booloperator < (const node& rhs) const { return v < rhs.v || (v == rhs.v && id == rhs.id); } } b[maxn];
intmain(){ int n, m; scanf("%d%d", &n, &m); int num = n * m; for (int i = 0; i < num; ++i) { scanf("%d", &a[i]); } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { b[j].Set(i * m + j); } sort(b, b + m); for (int j = 1; j < m; ++j) { int x = b[j].id; int y = b[j - 1].id; if (b[j].v == b[j - 1].v) { eq[x].push_back(y); eq[y].push_back(x); } else { mr[x].push_back(y); } } } for (int j = 0; j < m; ++j) { for (int i = 0; i < n; ++i) { b[i].Set(i * m + j); } sort(b, b + n); for (int i = 1; i < n; ++i) { int x = b[i].id; int y = b[i - 1].id; if (b[i].v == b[i - 1].v) { eq[x].push_back(y); eq[y].push_back(x); } else { mr[x].push_back(y); } } } for (int i = 0; i < num; ++i) { b[i].Set(i); } sort(b, b + num); for (int i = 0; i < num; ++i) { int id = b[i].id; if (vis[id]) { continue; } x[0] = id; vis[id] = true; int s = 0, e = 0; while (s <= e) { for (int u: eq[x[s]]) { if (!vis[u]) { x[++e] = u; vis[u] = true; } } ++s; } ++e; int put = 0; for (int j = 0; j < e; ++j) { for (int v: mr[x[j]]) { put = max(put, ans[v]); } } ++put; for (int j = 0; j < e; ++j) { ans[x[j]] = put; } } num = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { printf("%d ",ans[num++]); } puts(""); } return0; }