Cod sursa(job #632095)

Utilizator razvan_kusztosKusztos razvan razvan_kusztos Data 10 noiembrie 2011 12:07:09
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <cstdio>
#include <vector>
#define Mod 666013
using namespace std;
int n,op,x,i,ind;
vector<int> h[Mod];
vector<int>::iterator it;

vector<int>::iterator findv(int x)
{
     for (it=h[ind].begin() ; it!=h[ind].end() ;it++)
        if (*it==x) return it;
        return h[ind].end();
}
void insertv(int x)
{
    if (it==h[ind].end()) h[ind].push_back(x);
}
void erasev(int x)
{
    if (it!=h[ind].end()) h[ind].erase(it);
}
void writev(int x)
{
    if (it!=h[ind].end()) printf("1\n");
    else
    printf("0\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;
                it=findv(x);
                if (op==1) insertv(x);
                if (op==2) erasev(x);
                if (op==3) writev(x);
            }
    }