Cod sursa(job #1476156)

Utilizator SilviuIIon Silviu SilviuI Data 24 august 2015 15:39:02
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <stdio.h>
#include <vector>
#define mod 100313
using namespace std;
int tip,x,i,n;
vector <int> g[mod+5];
void insert_hash(int x)
{
    unsigned int i; int y=x%mod;
    for (i=0;i<g[y].size();i++)
        if (g[y][i]==x) return;
    g[y].push_back(x);
}
void delete_hash(int x)
{
    unsigned int i; int y=x%mod;
    for (i=0;i<g[y].size();i++)
       if (g[y][i]==x) { g[y].erase(g[y].begin()+i); return; }
}
bool inhash(int x)
{
    unsigned int i; int y=x%mod;
    for (i=0;i<g[y].size();i++)
        if (g[y][i]==x) return true;
    return false;
}
int main() {
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&n);
for (i=1;i<=n;i++) {
    scanf("%d %d",&tip,&x);
    if (tip==1) insert_hash(x); else
    if (tip==2) delete_hash(x); else
    {
        if (inhash(x)) puts("1"); else puts("0");
    }
}
return 0;
}