Cod sursa(job #912158)

Utilizator informatician28Andrei Dinu informatician28 Data 12 martie 2013 09:45:42
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.11 kb
#include <fstream>
#include <vector>

using namespace std;

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

#define MOD 666013

int N;
vector<int> G[MOD];

vector<int>::iterator find_value(int x)
{
    int rest = x % MOD;
    vector<int>::iterator it;
    for (it = G[rest].begin(); it != G[rest].end(); ++it)
    {
        if (*it == x)
        {
            return it;
        }
    }
    return G[rest].end();
}

void insert_value (int x)
{
    int rest = x % MOD;
    if (find_value(x) == G[rest].end())
    {
        G[rest].push_back(x);
    }
}

void delete_value (int x)
{
    int rest = x % MOD;
    vector<int>::iterator it = find_value(x);
    if (it != G[rest].end())
    {
        G[rest].erase(it);
    }
}

int main()
{
    int tip, x;

    in >> N;
    for (int i = 1; i <= N; i++)
    {
        in >> tip >> x;
        if (tip == 1)
        {
            insert_value(x);
        }
        else if (tip == 2)
        {
            delete_value(x);
        }
        else out << (find_value(x) != G[x % MOD].end()) << '\n';
    }
    return 0;
}