Cod sursa(job #934719)

Utilizator dumitrualexAlex Dumitru dumitrualex Data 31 martie 2013 11:17:00
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.14 kb
#include <cstdio>
#include <vector>
#define MOD 666013
using namespace std;

FILE * fin = freopen("hashuri.in", "r", stdin);
FILE * fout = freopen("hashuri.out", "w", stdout);

vector<int> hasht[MOD + 5];

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

void _insert(int x)
{
    int pos = x % MOD;
    if (_find(x) == hasht[pos].end())
        hasht[pos].push_back(x);
}

void _delete(int x)
{
    int pos = x % MOD;
    vector<int>::iterator it = _find(x);
    if (it != hasht[pos].end())
        hasht[pos].erase(it);
}
int main()
{
    int i, n, op, x;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d%d", &op, &x);

        switch (op)
        {
        case 1:
            _insert(x);
            break;
        case 2:
            _delete(x);
            break;
        case 3:
            printf("%d\n", _find(x) != hasht[x % MOD].end());
            break;
        }
    }
    return 0;
}