Cod sursa(job #1019160)

Utilizator Raba_SebastianRaba Sebastian Stefan Raba_Sebastian Data 30 octombrie 2013 18:59:49
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <vector>
#define MOD 666013
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector <int> G[MOD];
int N;
vector <int> :: iterator Find(int Val)
{
    int List=Val%MOD;
    for(vector <int> :: iterator it=G[List].begin();it!=G[List].end();it++)
            if(*it==Val)
                return it;
    return G[List].end();
}
void Insert(int Val)
{
    int List=Val%MOD;
    if(Find(Val)==G[List].end())
        G[List].push_back(Val);
}
void Delete(int Val)
{
    int List=Val%MOD;
    if(Find(Val)!=G[List].end())
        G[List].erase(Find(Val));
}
int main()
{
    fin>>N;
    while(N--)
    {
        int op,x;
        fin>>op>>x;
        if(op==1)
           Insert(x);
        if(op==2)
           Delete(x);
        if (op==3)
           if(Find(x)==G[x%MOD].end())
                fout<<0<<"\n";
           else
                fout<<1<<"\n";

    }
    return 0;
}