Cod sursa(job #1952447)

Utilizator matystroiaStroia Matei matystroia Data 4 aprilie 2017 09:45:14
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <fstream>
#include <map>
#include <vector>
using namespace std;

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

const int M=666013;

int n, op, x;
vector<int> m[M];

vector<int> t;

vector<int>::iterator fnd(int x)
{
    int k=x%M;
    for(vector<int>::iterator it=m[k].begin();it!=m[k].end();++it)
        if(*it==x) return it;
    return m[k].end();
}

void ins(int x)
{
    int k=x%M;
    if(fnd(x)==m[k].end())
        m[k].push_back(x);
}

void del(int x)
{
    int k=x%M;
    vector<int>::iterator it=fnd(x);
    if(it!=m[k].end())
        m[k].erase(it);
}

bool q(int x)
{
    int k=x%M;
    return fnd(x)!=m[k].end();
}

int main()
{
    fin>>n;
    for(int i=0;i<n;++i)
    {
        fin>>op>>x;

        if(op==1)
            ins(x);
        else if(op==2)
            del(x);
        else if(op==3)
            fout<<q(x)<<'\n';
    }
    return 0;
}