Cod sursa(job #750345)

Utilizator dutzulBodnariuc Dan Alexandru dutzul Data 21 mai 2012 21:43:56
Problema Sortare prin comparare Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.31 kb
#include <fstream>
#include <vector>
#include <cstdlib>
#include <ctime>
#define LE 100005
#include <algorithm>
#define ll long long
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int ind [LE+100];
vector <int> keys[LE+100];
vector <int> :: iterator it;
int i,tip,val,n,poZ;





////
int get_poz(int key,int poz)
{
  while (poz*2<=LE)
    {
      if (key<=ind[poz]) poz*=2;
      else if (2*poz+1<=LE) poz=2*poz+1;
    }
  return poz;
}

int push(int key)
{
  int k=get_poz(key,1);
  keys[get_poz(key,1)].push_back(key);
}

void build_tree(int st,int dr,int poz)
{
  int mij=(st+dr)/2;
  ind[poz]=mij;
  if (2*poz>LE) return;
  build_tree(st,mij,2*poz);
  build_tree(mij+1,dr,2*poz+1);
}

int Delete(int key)
{
  poZ=get_poz(key,1);
  for(it=keys[poZ].begin(); it!=keys[poZ].end(); ++it)
    if (*it==key)
      {
        keys[poZ].erase(it);
        break;
      }
}
int Search(int key)
{
  poZ=get_poz(key,1);

  for(it=keys[poZ].begin(); it!=keys[poZ].end(); ++it)
    if (*it==key)
      return 1;
  return 0;
}
int main()
{
  f>>n;
  build_tree(1,LE,1);

 for(i=1; i<=n; ++i)
    {
      //f>>tip;
      f>>val;
      //if (tip==1)
       push(val);
    }
    for(i=1;i<=n;++i) g<<1<<" ";

  f.close();
  g.close();
  return 0;
}