Pagini recente » Cod sursa (job #2616677) | Cod sursa (job #2919894) | Cod sursa (job #928470) | Cod sursa (job #496183) | Cod sursa (job #2615961)
#include <stdio.h>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;
ifstream fin ("algsort.in");
ofstream fout ("algsort.out");
const int Nmax = 500555;
int a[Nmax];
void mqsort(int l, int r) {
if (l >= r) { return; }
int m = l + rand() % (r-l+1);
int pivot = a[m];
int i = l, j = r;
while(i <= j) {
while(a[i] < pivot)
++i;
while(a[j] > pivot)
--j;
if(i <= j) {
swap(a[i], a[j]);
++i;
--j;
}
}
if (i < r) {
mqsort(i, r);
}
if (l < j) {
mqsort(l, j);
}
}
int main(void) {
// freopen("algsort.in", "r", stdin);
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int n;
fin >> n;
rep(i, n) {
fin >> a[i];
}
mqsort(0, n-1);
rep(i, n) {
fout << a[i] << " ";
}
fout << "\n";
return 0;
}