Cod sursa(job #1247858)

Utilizator savulescustefanSavulescu Stefan savulescustefan Data 24 octombrie 2014 11:03:33
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <cstdio>
#include <vector>
#define mod 666013
using namespace std;
vector <int> h[mod+5];
vector <int>::iterator it;
int op,x,i,n,ind;
void find1 (int x)
{
    for (it=h[ind].begin();it!=h[ind].end();it++)
        if (*it==x)
        return;
}
void insert1 (int x)
{
    if (it==h[ind].end())
        h[ind].push_back(x);
}
void erase1 (int x)
{
    if (it!=h[ind].end())
        h[ind].erase(it);
}
void write (int x)
{
    if (it==h[ind].end())
        printf ("0\n");
    else
        printf ("1\n");
}
int main()
{
    freopen ("hashuri.in","r",stdin);
    freopen ("hashuri.out","w",stdout);
    scanf ("%d", &n);
    for (i=1;i<=n;i++)
    {
        scanf ("%d %d", &op, &x);
        ind=x%mod;
        find1(x);
        if (op==1)
            insert1 (x);
        else if (op==2)
            erase1 (x);
        else
            write (x);
    }
    return 0;
}