Cod sursa(job #1503163)

Utilizator mlupseLupse-Turpan Mircea mlupse Data 15 octombrie 2015 17:46:16
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 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;

int Find(int Val)
{
    int List = Val % MOD;

    for(int i = 0; i < (int)V[List].size(); i++)
        if(V[List][i]==Val)
            return i;
    return -1;
}

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

void Delete(int Val)
{
    int List = Val % MOD;
    int Position = Find(Val);
    if(Position != -1)
        V[List].erase(V[List].begin()+Position);
}


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) != -1)<<"\n";
    }
    return 0;
}