Cod sursa(job #1218372)

Utilizator rangerChihai Mihai ranger Data 10 august 2014 19:12:22
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include<fstream>
#include<vector>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");

const int  P = 666013;
vector<int> H[P];
int n;

int h(int x) {
    return x % P;
    }


int find_(int x)
{
    int i;
    for (i=0;i<H[h(x)].size() && H[h(x)][i]!=x;i++);
    return (i<H[h(x)].size());
}

void Add(int x)
{
    if (!find_(x)) H[h(x)].push_back(x);
}

void pop(int x)
{
    for (int i=0;i<H[h(x)].size();i++)
    if (H[h(x)][i]==x) {
        H[h(x)][i]=-1;
        break;
    }
}

int main()
{
    cin>>n;
    for (;n--;)
    {
        int op,x;
        cin>>op>>x;
        if (op == 1)
            Add(x);
        if (op==2)
            pop(x);
        if (op==3)
            cout<<find_(x)<<"\n";
    }
    return 0;
}