Cod sursa(job #717235)

Utilizator mytzuskyMihai Morcov mytzusky Data 19 martie 2012 19:21:01
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <stdio.h>
#include <vector>

#define m 666013
using namespace std;

int n,op,x;
vector <int> v[m];

vector<int>::iterator cauta(int x)
{
    for(vector<int>::iterator it = v[x%m].begin() ; it != v[x%m].end() ; ++it)
        if(*it == x)
            return it;
    return v[x%m].end();
}

void adauga(int x){
    if(cauta(x) == v[x%m].end())
        v[x%m].push_back(x);
}

void sterge(int x){
    vector<int>::iterator searchedX = cauta(x);
    if(searchedX != v[x%m].end())
        v[x%m].erase(searchedX);
}

int main()
{
    freopen ("hashuri.in","r",stdin);
    freopen ("hashuri.out","w",stdout);

    scanf("%d", &n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d %d", &op, &x);

        if(op==1)       adauga(x);
        else if(op==2)  sterge(x);
        else            printf("%d\n", cauta(x)!=v[x%m].end());
    }
    return 0;
}