Cod sursa(job #2108225)

Utilizator ScarymovieMocanu Alexandru Scarymovie Data 17 ianuarie 2018 23:58:29
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include<bits/stdc++.h>
#define PRIM 666013
using namespace std;
vector<int> hashTable[PRIM];
int cauta(int x)
{
    for(unsigned i=0;i!=hashTable[x%PRIM].size();++i)
        if(x==hashTable[x%PRIM][i]) return i;
    return -1;
}
int main()
{
    int n,i,op,x,poz;
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    f>>n;
    for(i=0;i<n;++i)
        {
            f>>op>>x;
            if(op==1) {if(cauta(x)==-1) hashTable[x%PRIM].push_back(x);}
            else if(op==2) {int poz=cauta(x);if(poz>=0) hashTable[x%PRIM].erase(hashTable[x%PRIM].begin()+poz);}
            else g<<!(!(cauta(x)+1))<<'\n';
        }
    return 0;
}