Cod sursa(job #2268207)

Utilizator cezarzbughinCezar Zbughin cezarzbughin Data 24 octombrie 2018 16:30:40
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int N = 100003; /// un numar prim utilizat in tabela de dispersie ( tabela hash )

vector<int> H[N];
vector<int>::iterator it;
int n,o,x,h;
int main()
{
    f>>n;
    for(;n;n--)
    {
        f>>o>>x;
        h=x%N;
        for(it=H[h].begin();it!=H[h].end();it++)
            if(*it==x)
                break;
        if(o==1&&it==H[h].end())
            H[h].push_back(x);
        else if(o==2&&it!=H[h].end())
        {
            *it=H[h].back();
            H[h].pop_back();
        }
        else if(o==3)
        {
            if(it==H[h].end())
                g<<"0\n";
            else
                g<<"1\n";
        }
    }
    return 0;
}