Cod sursa(job #1197000)

Utilizator Cristian1997Vintur Cristian Cristian1997 Data 10 iunie 2014 10:53:43
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
using namespace std;
#include <fstream>
#include <vector>
#include <algorithm>
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

const int Nmax = 1000000;
const int P = 666013;

vector<int> L[P];

void push(int) ;
void sterge(int) ;
bool search1(int) ;

int main()
{
    int i, a, tip, n;
    fin>>n;
    for(i=0; i<n; ++i)
    {
        fin>>tip>>a;
        if(tip==1) push(a);
        if(tip==2) sterge(a);
        if(tip==3) fout<<search1(a)<<'\n';
    }
    return 0;
}


void push(int x)
{
    int hash = x%P;
    for(vector<int>::iterator it = L[hash].begin(); it!=L[hash].end(); ++it)
        if(*it == x) return;
    L[hash].push_back(x);
}


void sterge(int x)
{
    int hash = x%P;
    for(vector<int>::iterator it = L[hash].begin(); it!=L[hash].end(); ++it)
        if(*it == x)
        {
            L[hash].erase(it);
            return;
        }
}


bool search1(int x)
{
    int hash = x%P;
    for(vector<int>::iterator it = L[hash].begin(); it!=L[hash].end(); ++it)
        if(*it == x) return 1;
    return 0;
}