Cod sursa(job #2891286)

Utilizator mirceaspPetcu Mircea mirceasp Data 18 aprilie 2022 00:59:41
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <iterator>
using namespace std;
#define size 666073
vector<long long >h[size];
int cauta(long long x)
{
    int ok = 0;
    vector<long long > ::iterator i;
    for ( i = h[x%size].begin();i != h[x%size].end() && ok == 0;++i)
        if(*i == x)
            ok = 1;
    if(ok == 1)
      return 1;
    else
      return 0;
}
void adauga(long long x)
{
    if(cauta(x) == 1)
        return;
    else
        h[x%size].push_back(x);
}
void sterge(long long x)
{
    if(cauta(x) == 1)
        h[x%size].pop_back();
    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
            g<<cauta(x)<<'\n';


    }

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