Cod sursa(job #1152880)

Utilizator Dragan_ValentinDragan Valentin Dragan_Valentin Data 25 martie 2014 00:49:49
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#define div 666013

using namespace std;

vector <int> h[666014];

void add_hash(int x)
{
    h[x%div].push_back(x);
}

void remove_hash(int x)
{
    int i;
    for (i=0; i<h[x%div].size(); i++)
        if (h[x%div][i]==x) { h[x%div].erase(h[x%div].begin()+i); return; }
}

short search_hash(int x)
{
    int i;
    for (i=0; i<h[x%div].size(); i++)
        if (h[x%div][i]==x) return 1;
    return 0;
}

int main()
{
    int n,i;
    int op,x;
    freopen("hashuri.in","r",stdin);
    ofstream g("hashuri.out");
    scanf("%d",&n);
    for (i=0; i<n; i++) {
        scanf("%d %d",&op,&x);
        if (op==1) add_hash(x);
        else if (op==2) remove_hash(x);
        else g<<search_hash(x)<<'\n';
    }
    return 0;
}