Cod sursa(job #2896430)

Utilizator BVLUBogdan Ivan BVLU Data 29 aprilie 2022 22:55:16
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

#define mod 786433

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

int n;
vector <int> h[mod];

int cauta( int x )
{
    int n = h[ x % mod ].size();
    for( int i = 0; i < n; ++i )
        if( x == h[ x % mod ][i] )
            return i;
    return -1;
}

void adauga( int x )
{
    h[ x % mod ].push_back( x );
}

void sterge( int x )
{
    if( cauta( x ) != -1 )
        h[ x % mod ].erase( h[ x % mod ].begin() + cauta( x ) );
}

int main()
{
    f >> n;
    for( int i = 0; i < n; ++i )
    {
        int x, y;
        f >> x >> y;
        if( x == 1 )
            adauga( y );
        else if( x == 2 )
            sterge( y );
        else
            g << ( cauta( y ) != -1 ? 1 : 0 ) << "\n";
    }
    f.close();
    g.close();
    return 0;
}