Cod sursa(job #2747849)

Utilizator annesthesyaAnastasia Neagu annesthesya Data 29 aprilie 2021 18:11:11
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.97 kb
#include <fstream>
#include <vector>
#include <iterator>

using namespace std;

vector<int> h[666013];

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

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

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

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

void del(int x){
    int key=x%666013;
    vector<int>::iterator i = find(x);
    if (i!=h[key].end())
        h[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){
        del(val);
    }
    else if(x==3)
        g<<found(val)<<'\n';
    }

    return 0;
}