Mai intai trebuie sa te autentifici.
Cod sursa(job #2606736)
| Utilizator | Data | 28 aprilie 2020 14:11:44 | |
|---|---|---|---|
| Problema | Sortare prin comparare | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.86 kb |
#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
int t, n, m, k, q, l;
vector<ll> a;
void quick_sort(int l, int r){
int m=(l+r)/2;
if(l==r){return;}
if( a[l]>=a[r] ){swap(a[l], a[r] );}
if( a[m]<=a[l] ){ swap(a[l], a[m] ); }
quick_sort(l, m);
quick_sort(m+1, r);
for(int i=l; i<=r; i++){
if(a[i]<=a[max(1, i-1)] ){
swap(a[i], a[max(1, i-1)] );
}
}
return ;
}
int32_t main(){
INIT
cin>>n;
a.resize(n+5);
for(int i=1; i<=n; i++){
cin>>a[i];
}
quick_sort(1, n);
for(int i=1; i<=n; i++){
cout<<a[i]<<" ";
}
return 0;
}
