Cod sursa(job #1039437)

Utilizator morlockRadu Tatomir morlock Data 23 noiembrie 2013 00:14:58
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <iostream>
#include <vector>
#include <fstream>
#define nmax 1000005
#define loc x%P
using namespace std;

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

long N, key, x;
const long P = 666013;
vector <long> H[P];

bool find(int x)
{

    for ( unsigned int i=0; i < H[loc].size(); ++i )
        if ( H[loc][i] == x ) return 1;

    return 0;
}

void insert(int x)
{
    if ( !find(x) )
        H[loc].push_back(x);
}

void erase(int x)
{
    for ( unsigned int i=0; i < H[loc].size(); ++i )
        if ( H[loc][i] == x )
        {
            H[loc][i] = H[loc].back();
            H[loc].pop_back();
        }
}


int main()
{
    in >> N;

    for ( int i=1; i<=N; ++i )
    {
        in >> key >> x;

        if ( key == 1 ) insert(x);
        if ( key == 2 ) erase(x);
        if ( key == 3 ) out << find(x) << '\n';

    }

return 0;
}