Cod sursa(job #2941489)

Utilizator bogdan.schiopBogdan Schiop bogdan.schiop Data 17 noiembrie 2022 20:05:51
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.21 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

int n, com, x;

vector<int> hashuri[666013];

bool cautare(int x)
{
    int f = x % 666013;
    vector<int>::iterator i = hashuri[f].begin();
    while(i != hashuri[f].end())
    {
        if(*i == x)
            return 1;
        i++;
    }
    return 0;
}

void adaugare(int x)
{
    if(cautare(x) == 1) return;
    hashuri[x%666013].push_back(x);
}

void eliminare(int x)
{
    if(cautare(x) == 0) return;
    int f = x % 666013;
    vector<int>::iterator i = hashuri[f].begin();
    while(i != hashuri[f].end())
    {
        if(*i == x)
        {
            hashuri[f].erase(i);
            return;
        }
        i++;
    }

}

void rezolvare()
{
    fin >> n;
    for(int i = 1; i <= n; i++)
    {
        fin >> com >> x;
        switch(com)
        {
        case 1:
            adaugare(x);
            break;
        case 2:
            eliminare(x);
            break;
        case 3:
            fout << cautare(x) << '\n';
            break;
        }
    }

}

int main()
{
    rezolvare();
    return 0;
}