Cod sursa(job #2219155)

Utilizator bojemoiRadu Mamaliga bojemoi Data 7 iulie 2018 15:37:21
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include<fstream>
#include<vector>
#define prim 9699691
using namespace std;

ifstream cin("hashuri.in");
ofstream cout("hashuri.out");

vector <long> Hash[prim];
int n;

bool cauta(long x){
    int rest = x % prim;
    for(int i = 0; i<Hash[rest].size(); ++i){
        if(Hash[rest][i] == x) return 1;
    }
    return 0;
}

void push(long x){
    if(cauta(x)==0){
         Hash[x%prim].push_back(x);
    }
}
void sterge(long x){
    int rest = x%prim;
    for(int i = 0; i<Hash[rest].size(); ++i){
        if(Hash[rest][i]==x){
            Hash[rest].erase(Hash[rest].begin() + i);
            return;
        }
    }
}



int main()
{
    cin>>n;

    while(n--){
        int op;
        long x;
        cin>>op;
        cin>>x;
        if(op==1){
            push(x);
        }
        else if(op==2){
            sterge(x);
        }
        else{
            cout<<cauta(x)<<'\n';
        }
    }



    return 0;
}