Pagini recente » Cod sursa (job #1759372) | Cod sursa (job #1172180) | Cod sursa (job #267846) | Cod sursa (job #1211295) | Cod sursa (job #1290488)
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "algsort";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif // HOME
typedef long long int lld;
typedef pair<int, int> PII;
typedef pair<int, lld> PIL;
typedef pair<lld, int> PLI;
typedef pair<lld, lld> PLL;
const int INF = (1LL << 30) - 1;
const lld LINF = (1LL << 62) - 1;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int MOD = (int)(1e9) + 7;
const int NMAX = 500000 + 5;
const int MMAX = 100000 + 5;
const int KMAX = 100000 + 5;
const int PMAX = 100000 + 5;
const int LMAX = 100000 + 5;
const int VMAX = 100000 + 5;
int N;
int V[NMAX];
void qsort(int lo, int hi) {
if(lo >= hi)
return;
int p = V[lo + (rand() % (hi - lo + 1))];
int i, j;
for(i = lo, j = hi; i < j;) {
while(V[i] < p)
i++;
while(V[j] > p)
j--;
if(i <= j) {
swap(V[i], V[j]);
i++;
j--;
}
}
qsort(lo, j);
qsort(i, hi);
}
int main() {
int i;
#ifndef ONLINE_JUDGE
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
#endif
srand(time(0));
scanf("%d", &N);
for(i = 1; i <= N; i++)
scanf("%d", &V[i]);
qsort(1, N);
for(i = 1; i <= N; i++)
printf("%d ", V[i]);
return 0;
}