Cod sursa(job #1490868)

Utilizator DenisONIcBanu Denis Andrei DenisONIc Data 24 septembrie 2015 12:00:29
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <cstdio>
#include <vector>
#define MOD 100003
using namespace std;


long n,i,t,x;
vector<long> h[100005];

void Hadd(long x)
{
    for (int i=0;i<h[x%MOD].size();i++)
        if (h[x%MOD][i]==x)
            return;
    h[x%MOD].push_back(x);
}

void Hdel(long x)
{
    for (int i=0;i<h[x%MOD].size();i++)
        if (h[x%MOD][i]==x)
            h[x%MOD].erase(h[x%MOD].begin()+i);
}

bool Hquery(long x)
{
    for (int i=0;i<h[x%MOD].size();i++)
        if (h[x%MOD][i]==x)
            return 1;
    return 0;
}

int main()
{
    freopen ("hashuri.in","r",stdin);
    freopen ("hashuri.out","w",stdout);

    scanf("%ld",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%ld%ld",&t,&x);
        if (t==1)
            Hadd(x);
        else if (t==2)
            Hdel(x);
        else
            printf("%ld\n",Hquery(x));
    }


    return 0;
}