Cod sursa(job #2617202)

Utilizator iuliaaa2110Barbu Iulia Andreea iuliaaa2110 Data 20 mai 2020 22:27:37
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include<iostream>
#include<fstream>
//#include <unordered_set>
#include<vector>

using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");

#define prim 666013

vector<int> hash_[prim+1];

bool f3(int x)  //find
{
    int mod=x%prim;

    for(int i=0;i<hash_[mod].size();i++)
        if(x==hash_[mod][i])
            return true;
    return false;
}

void f1(int x)
{

    if(!f3(x))
        hash_[x%prim].push_back(x);

}

void f2(int x)
{
    int mod=x%prim;

    vector<int>::iterator t;

    for (t=hash_[mod].begin(); t!= hash_[mod].end(); ++t)
        if(*t==x)
        {
            hash_[mod].erase(t);
            break;
        }
}

int main ()
{

    int n,c,x;

    f>>n;

    for(int i=0;i<n;i++)
    {
        f>>c>>x;

        if(c==1)
            f1(x);
        if(c==2)
            f2(x);
        if(c==3)
            g<<f3(x)<<'\n';
    }

    return 0;

}