Cod sursa(job #2142405)

Utilizator sulzandreiandrei sulzandrei Data 24 februarie 2018 23:13:29
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
#define pb push_back
ifstream in ("hashuri.in");
ofstream out("hashuri.out");
const int M  =195931;
vector<int> v[M];
int H(int k ){return k % M;}
int exists(int hx,int e){ return find(v[ hx ].begin(),v[hx].end(),e) != v[ hx].end();}
void add(int &e)
{
    int hx = H(e);
    if (!exists(hx,e))
        v[ hx ].pb(e);
}
void erase(int &e)
{
    int hx = H(e);
    if ( exists(hx,e))
        v[ hx ].erase(find(v[ hx  ].begin(),v[hx ].end(),e));
}

int main()
{
    int n,x,op;
    in >> n;
    for(int i = 0 ; i < n ; i++)
    {
        in >> op >> x;
        switch(op)
        {
            case 1:add(x);break;
            case 2:erase(x);break;
            case 3:out<<exists(H(x),x)<<'\n';break;
        }
    }
    return 0;
}