Cod sursa(job #848449)

Utilizator blechereyalBlecher Eyal blechereyal Data 5 ianuarie 2013 14:59:01
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
using namespace std;
#include <fstream>
#include <vector>

ifstream f("hashuri.in");
ofstream g("hashuri.out");

vector <int> hash[666013];
vector <int>::iterator poz;

int find(int x)
{
int k=x%666013;

for (poz=hash[k].begin();poz!=hash[k].end();poz++)
  if (*poz==x) return 1;
return 0;
}

void add(int x)
{int k=x%666013;
if (!find(x)) hash[k].push_back(x);
}

void del(int x)
{
int k=x%666013;
vector<int>::iterator it;
if (find(x)) hash[k].erase(poz);
}

int main()
{int n,i,op,x;
f>>n;
for (i=1;i<=n;i++)
    {
    f>>op>>x;
    switch (op)
           {case 1:add(x); break;
           case 2:del(x); break;
           case 3:g<<find(x)<<"\n"; break;
           }
    }
return 0;
}