Cod sursa(job #874610)

Utilizator zalmanDanci Emanuel Sebastian zalman Data 9 februarie 2013 00:15:09
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <stdio.h>
#include <vector>

using namespace std;
#define MOD 666013

int N;
vector<int> T[MOD];
vector<int>::iterator it;

bool find_value(int value)
{
    int pos = value % MOD;

    for(it = T[pos].begin(); it != T[pos].end(); ++it)
        if(*it == value)
            return true;

    return false;
}

void insert_value(int value)
{
    int pos = value % MOD;

    if(!find_value(value))
        T[pos].push_back(value);
}

void remove_value(int value)
{
    int pos = value % MOD;

    for(it = T[pos].begin(); it != T[pos].end(); ++it)
        if(*it == value)
        {
            T[pos].erase(it);
            return;
        }
    
}
int main(int argc, const char *argv[])
{
    int op, val;

    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    
    for(scanf("%d", &N); N; --N)
    {
        scanf("%d %d", &op, &val);
        if(op == 1)
            insert_value(val);
        else
            if(op == 2)
                remove_value(val);
            else
                printf("%d\n", find_value(val));
    }

    fcloseall();
    return 0;
}