Cod sursa(job #2263660)

Utilizator AlexandruGabrielAliciuc Alexandru AlexandruGabriel Data 18 octombrie 2018 23:04:40
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.02 kb
#include <bits/stdc++.h>
#define mod 666013

using namespace std;

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

int n, x, op;
vector <int> H[mod + 5];

bool Verifica (int x)
{
    int r = x % mod;
    for (int i = 0; i < H[r].size(); i++)
        if (H[r][i] == x) return 1;
    return 0;
}

void Adauga (int x)
{
    if (!Verifica(x))
    {
        int r = x % mod;
        H[r].push_back(x);
    }
}

void Sterge (int x)
{
    int r = x % mod;
    for (int i = 0; i < H[r].size(); i++)
    {
        if (H[r][i] == x)
        {
            vector <int>::iterator it;
            it = H[r].begin() + i;
            H[r].erase(it);
        }
    }
}

int main()
{
    fin >> n;
    for (int i = 1; i <= n; i++)
    {
        fin >> op >> x;
        if (op == 1)
        {
            Adauga(x);
        }
        else if (op == 2)
        {
            Sterge(x);
        }
        else if (op == 3)
            fout << Verifica(x) << "\n";
    }
    return 0;
}