Cod sursa(job #1213659)

Utilizator pop_bogdanBogdan Pop pop_bogdan Data 28 iulie 2014 18:13:04
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.32 kb
#include <fstream>
#include <vector>
using namespace std;

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

#define fi first
#define se second
#define MOD 666013

void Insert(int);
void Erase(int);
bool Find(int);
vector <int>:: iterator it;

inline int Hash(int x)
{
    return x%MOD;
}

int N;
vector <int> G[MOD];
pair<int,int> c;
int cnt;

int main()
{
    is >> N;
    for ( int i = 1; i <= N; ++i )
    {
        is >> c.fi >> c.se;
        if ( c.fi == 1 )
        {
            Insert(c.se);
            continue;
        }
        if ( c.fi == 2 )
        {
            Erase(c.se);
            continue;
        }
        os << Find(c.se) << '\n';
    }

    is.close();
    os.close();
}

void Insert(int x)
{
    cnt = Hash(x);
    for ( it = G[cnt].begin(); it != G[cnt].end(); ++it )
    {
        if ( *it == x )
            return;
    }
    G[cnt].push_back(x);
}

void Erase(int x)
{
    cnt = Hash(x);
    for ( it = G[cnt].begin(); it != G[cnt].end(); ++it )
    {
        if ( *it == x )
        {
            G[cnt].erase(it);
            return;
        }
    }
}

bool Find(int x)
{
    cnt = Hash(x);
    for ( it = G[cnt].begin(); it != G[cnt].end(); ++it )
    {
        if ( *it == x )
            return true;
    }
    return false;
}