Cod sursa(job #2891292)

Utilizator mirceaspPetcu Mircea mirceasp Data 18 aprilie 2022 01:25:21
Problema Hashuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.05 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <iterator>
using namespace std;
#define size 666073
vector<long long >h[size];
vector<long long >::iterator cauta(long long x)
{
    vector<long long > ::iterator i;
    for ( i = h[x%size].begin();i != h[x%size].end();++i)
        if(*i == x)
            return i;
    return h[x%size].end();
}
void adauga(long long x)
{
    if(cauta(x) != h[x%size].end())
        return;
    else
        h[x%size].push_back(x);
}
void sterge(long long x)
{
    if(cauta(x) != h[x%size].end())
        h[x%size].erase(cauta(x));
    else
        return;
}
int main() {
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    long long n,op,x;
    f>>n;
    while (f>>op>>x)
    {
         if(op == 1)
                adauga(x);
         else if(op == 2)
                sterge(x);
         else
            if(cauta(x) == h[x%size].end())
                g<<0<<'\n';
            else
                g<<1<<'\n';

    }

    f.close();g.close();
    return 0;
}