Mai intai trebuie sa te autentifici.
Cod sursa(job #1046970)
| Utilizator | Data | 3 decembrie 2013 19:17:04 | |
|---|---|---|---|
| Problema | Hashuri | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.95 kb |
#include <cstdio>
#include<vector>
#define MOD 666013
using namespace std;
vector <int> H[MOD];
int caut(int x)
{
int h = x % MOD;
for(size_t i=0;i<H[h].size();++i)
if(H[h][i]==x)
return i;
return -1;
}
void adaug(int x)
{
int h = x % MOD;
if(caut(x)==-1)
H[h].push_back(x);
}
void sterg(int x)
{
int h = x % MOD;
if(caut(x)>-1)
H[h].erase(H[h].begin()+caut(x));
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int n;
scanf("%d",&n);
while(n--)
{
int op,x;
scanf("%d %d",&op,&x);
switch(op)
{
case 1:
adaug(x);
break;
case 2:
sterg(x);
break;
case 3:
printf("%d\n",caut(x)>-1);
break;
}
}
return 0;
}
