wu

chl2023 2023-10-21 10:41:17

#include <bits/stdc++.h>

using namespace std;

const int maxn = 200000 + 5;

int n;
int a[maxn];

void msort(int l, int r) {
  if (l == r) return;
  int mid = (l + r) / 2;
  msort(l, mid);
  msort(mid + 1, r);
  int tmp[n];
  int i=l,j=mid+1;
      int k=0;
      while(i<=mid && j<=r){
          if(a[i]<=a[j])  tmp[k++] = a[i++];
          else  tmp[k++] = a[j++];
      }
      while(i<=mid)  tmp[k++] = a[i++];
      while(j<=r)   tmp[k++] = a[j++];
      
      
      for(int i=l,j=0;i<=r;i++,j++) a[i]=tmp[j];
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  msort(1, n);
  for (int i = 1; i <= n; i++) cout << a[i] << ' ';
  cout << endl;

  return 0;
}