Cod sursa(job #1503170)

Utilizator mlupseLupse-Turpan Mircea mlupse Data 15 octombrie 2015 17:50:16
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <fstream>
#include <vector>
using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

const int MOD = 666013;
vector <int> V[MOD];
int N;

vector <int> :: iterator Find(int Val)
{
    int List = Val % MOD;

    vector <int> :: iterator it;

    for(it = V[List].begin(); it != V[List].end(); it++)
      if(*it == Val)
            return it;
    return V[List].end();
}

void Insert(int Val)
{
    int List = Val % MOD;
    if(Find(Val) == V[List].end())
        V[List].push_back(Val);
}

void Delete(int Val)
{
    int List = Val % MOD;
    vector <int> :: iterator it = Find(Val);
    if(it != V[List].end())
        V[List].erase(it);
}


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)
            fout << (Find(x) != V[x%MOD].end())<<"\n";
    }
    return 0;
}