Cod sursa(job #2617990)

Utilizator hirneagabrielHirnea Gabriel hirneagabriel Data 23 mai 2020 14:23:25
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.16 kb
#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int nr = 650000;

vector <int> Hash[nr];

int Find(int x)
{
    int i = x % nr;
    vector <int>::iterator j;
    for (j = Hash[i].begin(); j != Hash[i].end(); i++)
        if (*j == x)
            return 1;
    return 0;
}

void Insert(int x)
{

    if (Find(x) == 0)
    {
        int i =x%nr ;
        Hash[i].push_back(x);
    }
}

void Delete(int x)
{
    int i = x%nr;
    vector <int>::iterator j;
    for (j = Hash[i].begin(); j != Hash[i].end(); i++)
    {
        if (*j == x)
        {
            break;
        }
    }
    if (j != Hash[i].end())
        Hash[i].erase(j);
}


int main() {
    int N, x, y;
    fin >> N;
    while (N)
    {
        fin >> x;
        if (x == 1)
        {
            fin >> y;
            Insert(y);
        }
        if (x == 2)
        {
            fin >> y;
            Delete(y);
        }
        if (x == 3)
        {
            fin >> y;
            fout << Find(y) << "\n";
        }
        N--;
    }
    return 0;
}