Cod sursa(job #2037574)

Utilizator Stoica_StefanStoica Stefan Stoica_Stefan Data 12 octombrie 2017 15:53:07
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

const int M = 666013;
vector<int> h[M + 5];

int _hash(int k)
{
    return k % M;
}

bool search(int l, int k)
{
    for(int i = 0; i < h[l].size(); i++)
        if(h[l][i] == k)
            return 1;
    return 0;
}

void _delete(int l, int k)
{
    for(int i = 0; i < h[l].size(); i++)
        if(h[l][i] == k)
        {
            h[l].erase(h[l].begin() + i);
            return;
        }
}

int main()
{
    int n, x, k;
    fin >> n;
    for(int i = 0; i < n; i++)
    {
        fin >> x >> k;
        if(x == 1)
        {
            if(!search(_hash(k), k))
                h[_hash(k)].push_back(k);
        }else if(x == 2)
        {
            _delete(_hash(k), k);
        }else
        {
            if(search(_hash(k), k))
                fout << 1 << "\n";
            else
                fout << 0 << "\n";
        }
    }
    return 0;
}