/** * @version: * @author: @Akari * @date: 2024-01-22 11:50:34 **/ #include<bits/stdc++.h> #define deb(x) cout << #x << " = " << x << '\n'; #define INF 0x3f3f3f3f #define endl '\n' #define int long long usingnamespace std;
constint N = 1e6 + 10; int n, q[N], tmp[N]; voidmerge_soft(int q[], int l, int r);
signedmain(void) { scanf("%lld", &n); for (int i = 0; i < n; i ++ ) scanf("%lld", &q[i]); merge_soft(q, 0, n - 1); for (int i = 0; i < n; i ++ ) printf("%lld ", q[i]); return0; }
voidmerge_soft(int q[], int l, int r){ if (l >= r) return; int mid = (l + (r - l) / 2); merge_soft(q, l, mid); merge_soft(q, mid + 1, r); int k = 0, i = l, j = mid + 1; while (i <= mid && j <= r) if (q[i] <= q[j]) tmp[k ++ ] = q[i ++ ]; else tmp[k ++ ] = q[j ++ ]; while (i <= mid) tmp[k ++ ] = q[i ++ ]; while (j <= r) tmp[k ++ ] = q[j ++ ]; for (i = l, j = 0; i <= r; i ++, j ++) q[i] = tmp[j]; }