Cod sursa(job #2044006)

Utilizator rangal3Tudor Anastasiei rangal3 Data 20 octombrie 2017 20:21:44
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <fstream>
#include <vector>
#define file "hashuri"
#define MOD 777013
using namespace std;

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

int n,p,x;

vector<int> v[MOD];
vector<int>::iterator it,it2;

inline vector<int>::iterator cauta(int x)
{
    int pos = x%MOD;

    for(it2 = v[pos].begin(); it2 != v[pos].end(); ++it2)
        if(x == *it2) return it2;

    return v[pos].end();
}

inline void adauga(int x)
{
    int pos = x%MOD;
    if(cauta(x) == v[pos].end())
        v[pos].push_back(x);
}

inline void sterge(int x)
{
    int pos = x%MOD;
    it = cauta(x);
    if(it != v[pos].end())
        v[pos].erase(it);
}

int main()
{
    fin>>n;
    while(n--)
    {
        fin>>p>>x;
        if(p == 1) adauga(x);
        else if(p == 2) sterge(x);
        else if(cauta(x) != v[x%MOD].end())
                fout<<"1\n";
        else fout<<"0\n";
    }

    return 0;
}