Cod sursa(job #750310)

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





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

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

int build_tree()
{
  srand(time(0));
  for(i=1; i<=LE; ++i)
    ind[i]=(rand()*rand())%LE;
}

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();

  for(i=1; i<=n; ++i)
    {
      f>>tip>>val;
      if (tip==1) push(val);
      if (tip==2) Delete(val);
      if (tip==3) g<<Search(val)<<'\n';
    }


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