Cod sursa(job #2329553)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 26 ianuarie 2019 22:16:46
Problema Hashuri Scor 100
Compilator cpp-64 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> H[MOD + 5];

int N;

int Search(int Val)
{
    int L = Val % MOD;

    for(int i = 0; i < H[L].size(); i++)
        if(H[L][i] == Val)
            return i;

    return -1;
}

void Insert(int Val)
{
    int L = Val % MOD;

    if(Search(Val) == -1)
        H[L].push_back(Val);
}

void Delete(int Val)
{
    int L = Val % MOD, P = Search(Val);

    if(P != -1) H[L].erase(H[L].begin() + P);
}

int main()
{
    fin >> N;

    while(N--)
    {
        int t, x;

        fin >> t >> x;

        if(t == 1)
            Insert(x);
        if(t == 2)
            Delete(x);
        if(t == 3)
            fout << (Search(x) != -1) << '\n';
    }

    fin.close();
    fout.close();

    return 0;
}