Cod sursa(job #2182530)

Utilizator RaduVFVintila Radu-Florian RaduVF Data 22 martie 2018 14:10:41
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int MOD = 666013;
list < int > v[MOD];

inline bool Gasire(int x) {
    int hashCode=x%MOD;
    list<int>::iterator it;
    for(it=v[hashCode].begin(); it!=v[hashCode].end(); it++)
        if(*it==x)
            return true;
    return false;
}

inline void Inserare(int x) {
    int hashCode=x%MOD;
    if(!Gasire(x))
        v[hashCode].push_back(x);
}

inline void Stergere(int x) {
    int hashCode=x%MOD;
    list<int>::iterator it;
    for(it=v[hashCode].begin(); it!=v[hashCode].end(); it++)
        if(*it==x) {
            v[hashCode].erase(it);
            return;
        }
}
int main()
{
    int n,op,x;
    fin>>n;
    while(n--) {
        fin>>op>>x;
        if(op==1)
            Inserare(x);
        if(op==2)
            Stergere(x);
        if(op==3)
            fout<<Gasire(x)<<endl;
    }
    return 0;
}