Cod sursa(job #641698)

Utilizator andumMorie Daniel Alexandru andum Data 29 noiembrie 2011 10:51:04
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include <fstream>
#include <vector>

const int P = 666013;

using namespace std;

vector <int> V[1000000%P];

inline vector <int>::iterator find(int x)
{
       vector <int>::iterator it;
       int list=x%P;
       
       for (it=V[list].begin(); it!=V[list].end(); ++it)
           if (*it==x)
              return it;
       return V[list].end();
}

inline void insert(int x)
{
       int list=x%P;
       
       if (find(x)==V[list].end())
          V[list].push_back(x);
}

inline void erase(int x)
{
       vector <int>::iterator it = find(x);
       int list=x%P;
       
       if (it!=V[list].end())
          V[list].erase(it);
}

int main(int argc, char *argv[])
{
    int n,op,x;
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    
    f>>n;
    for (int i=0; i<n; ++i)
    {
        f>>op>>x;
        if (op==1)
           insert(x);
        if (op==2)
           erase(x);
        if (op==3)
           g<<(find(x)!=V[x%P].end())<<'\n';
    }
    
    return EXIT_SUCCESS;
}