Cod sursa(job #1479914)

Utilizator Vlad_lsc2008Lungu Vlad Vlad_lsc2008 Data 1 septembrie 2015 17:35:43
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include <cstdio>
#include <vector>
#define mod 524287
using namespace std;

vector<int> h[mod];
int n;

vector<int>::iterator find_it(int x)
{
    int poz=x%mod;
    vector<int>::iterator it;
    for(it=h[poz].begin();it<h[poz].end();it++) if(*it==x) return it;
    return h[poz].end();
}

void insert_it(int x)
{
    int poz=x%mod;
    if(find_it(x)==h[poz].end()) h[poz].push_back(x);
}

void erase_it(int x)
{
    int poz=x%mod;
    vector<int>::iterator it=find_it(x);
    if(it!=h[poz].end()) h[poz].erase(it);
}

int main()
{
    int tip,nr,i;
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    for(scanf("%d",&n);n;n--)
    {
        scanf("%d%d",&tip,&nr);
        if(tip==1) insert_it(nr);
        if(tip==2) erase_it(nr);
        if(tip==3)
            if(find_it(nr)==h[nr%mod].end()) printf("0\n");
                                        else printf("1\n");
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}