Cod sursa(job #2747838)

Utilizator annesthesyaAnastasia Neagu annesthesya Data 29 aprilie 2021 18:07:33
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <iterator>

using namespace std;

vector<int> hash[666013];

vector<int>::iterator find(int x){
    int key=x%666013;
    vector<int>::iterator i;

    for (i=hash[key].begin();i!=hash[key].end();i++)
        if (*i==x)
            return i;
    return hash[key].end();
}

int found(int x){
    int key=x%666013;
    if (find(x)==hash[key].end())
        return 0;
    return 1;
}

void add(int x){
    int key=x%666013;
    if (find(x)==hash[key].end())
        hash[key].push_back(x);
}

void remove(int x){
    int key=x%666013;
    vector<int>::iterator i = find(x);
    if (i!=hash[key].end())
        hash[key].erase(i);
}

int main(){
int n,x,val;

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

f>>n;
for (int i=1;i<=n;i++){
    f>>x;
    f>>val;
    if (x==1){
        add(val);
    }
    else if (x==2){
        remove(val);
    }
    else if(x==3)
        g<<found(val)<<'\n';
    }

    return 0;
}