提交时间:2024-03-09 11:13:52
运行 ID: 136626
#include <bits/stdc++.h> using namespace std; struct Node{ int x, y; bool operator < (const Node &o) const { if (x != o.x) return x < o.x; return y < o.y; } }; const int N = 1e6 + 005; Node a[N], b[N]; void mergeSort(int s, int t) { if (s == t) return; int mid = s + t >> 1; mergeSort(s, mid); mergeSort(mid + 1, t); int i = s, j = mid + 1, k = s; while (i <= mid && j <= t) if (a[i] < a[j]) b[k++] = a[i++]; else b[k++] = a[j++]; while (i <= mid) b[k++] = a[i++]; while (j <= t) b[k++] = a[j++]; for (int i = s; i <= t; i++) a[i] = b[i]; } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; mergeSort (1, n); for (int i = 1; i <= n; i++) cout << a[i].x << " " << a[i].y << "\n"; return 0; }