Cod sursa(job #2397635)

Utilizator IoanaDraganescuIoana Draganescu IoanaDraganescu Data 4 aprilie 2019 17:26:08
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int MOD = 666013;
vector <int> G[MOD + 5];
int N;
int Find(int Value)
{
    int List = Value % MOD;
    for(int i = 0; i < (int)G[List].size(); ++i)
        if(G[List][i] == Value)
            return i;
    return -1;
}

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

void Delete(int Value)
{
    int List = Value % MOD;
    int Index = Find(Value);
    if(Index != -1)
        G[List].erase(G[List].begin() + Index);
}

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;
}