Cod sursa(job #2624141)

Utilizator mihai_radulescuMihai Radulescu mihai_radulescu Data 4 iunie 2020 15:45:10
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

vector<int> hasht[66013];

void Add(int x){
    hasht[x % 66013].push_back(x);
}

void Delete(int x){
    int m = x % 66013;
    for (int i = 0; i < hasht[m].size(); i++)
        if(hasht[m][i] == x)
            hasht[m].erase(hasht[m].begin()+i);

}

int Search(int x){
    int m = x % 66013;
    for (int i = 0; i < hasht[m].size(); i++)
        if(hasht[m][i] == x)
            return 1;


    return 0;
}


int main()
{
    int n, x, y;
    f>>n;
    for(; n; n--){
        f >> x >> y;
        if(x == 1)
           Add(y);
        else
            if(x == 2)
                Delete(y);
            else
                g << Search(y) << '\n';

        }
}