Cod sursa(job #1604671)

Utilizator tudormaximTudor Maxim tudormaxim Data 18 februarie 2016 14:35:14
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

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

const int mod = 666013;
vector <int> h[mod];
int key;

vector <int> :: iterator Find(const int &x)
{
    vector <int> :: iterator it;
    for(it=h[key].begin(); it!=h[key].end(); it++)
        if(*it==x) return it;
    return h[key].end();
}

inline void Add(const int &x)
{
    if(Find(x)==h[key].end())
        h[key].push_back(x);
}

inline void Delete(const int &x)
{
    vector <int> :: iterator it;
    it=Find(x);
    if(it!=h[key].end())
        h[key].erase(it);
}

inline bool Exist(const int &x)
{
    if(Find(x)!=h[key].end()) return true;
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, op, i, x, poz;
    fin >> n;
    for(i=1; i<=n; i++)
    {
        fin >> op >> x;
        key=x%mod;
        if(op==1) Add(x);
        if(op==2) Delete(x);
        if(op==3) fout << Exist(x) << "\n";
    }
    fin.close();
    fout.close();
    return 0;
}