康复训练
#include <iostream>
using namespace std;
const int N = 100010;
int n;
int tmp[N], q[N];
void f(int l, int r) {
if (l >= r) return;
int mid = (l + r) >> 1;
f(l, mid), f(mid + 1, r);
int i = l, j = mid + 1, k = 0;
while (i <= mid && j <= r) {
if (q[j] < q[i]) tmp[k++] = q[j++];
else tmp[k++] = q[i++];
}
while (i <= mid) tmp[k++] = q[i++];
while (j <= r) tmp[k++] = q[j++];
for (i = 0, j = l; j <= r; ++i, ++j) q[j] = tmp[i];
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> q[i];
f(1, n);
for (int i = 1; i <= n; ++i) cout << q[i] << " ";
return 0;
}