Pagini recente » Cod sursa (job #3307491) | Cod sursa (job #3334450) | Cod sursa (job #3211405) | Cod sursa (job #1764579) | Cod sursa (job #2089979)
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int v[500050], n, m,poz,idx[2000050];
void afisare()
{int i=1;
while(i<=3*n)
cout<<v[i]<<" ",i++;
cout<<'\n';
}
void update(int l, int r, int nod,int poz)
{
if(l==r)
{ idx[nod]=poz;
return;
}
int mid=(l+r)/2;
if(poz<=mid)
update(l, mid, 2*nod, poz);
else
update(mid+1,r, 2*nod+1, poz);
if(v[idx[nod*2]]<v[idx[nod*2+1]])
idx[nod]=idx[nod*2];
else
idx[nod]=idx[nod*2+1];
}
void citire ()
{
f>>n;
int i,x;
for(i=1;i<=n;++i)
{
f>>v[i];
update(1,n,1,i);
}
f.close();
}
int main ()
{
citire();
int i;
for(i=1;i<=n;++i)
{
g<<v[idx[1]]<<" ";
v[idx[1]]=INT_MAX;
update(1,n,1,idx[1]);
}
g.close();
}