Pagini recente » Cod sursa (job #425217) | Cod sursa (job #3217730) | Cod sursa (job #1300017) | Cod sursa (job #3230868) | Cod sursa (job #806467)
Cod sursa(job #806467)
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#define BIG 666001
using namespace std;
vector <long> hash[BIG];
long find(long x)
{
long mod = x % BIG;
for (long i=0;i<hash[mod].size();i++)
{
if (hash[mod][i] == x) return i;
}
return -1;
}
void add(long x)
{
long mod = x % BIG;
if (find(x) == -1)
{
hash[mod].push_back(x);
}
}
void erase(long x)
{
long mod = x % BIG;
if (long poz = find(x) != -1 )
{
long fin = hash[mod].size() - 1;
long aux = hash[mod][fin];
hash[mod][fin] = hash[mod][poz];
hash[mod][poz] = aux;
hash[mod].pop_back();
}
}
int main()
{
FILE *input = fopen("hashuri.in","r");
FILE *output = fopen("hashuri.out","w");
long n;
fscanf(input,"%ld",&n);
for (long i=0;i<n;i++)
{
int op;
long x;
fscanf(input,"%d",&op);
fscanf(input,"%ld",&x);
if (op == 1)
{
add(x);
}
if (op == 2)
{
erase(x);
}
if (op == 3)
{
long rasp = find(x);
if (rasp != -1) fprintf(output,"%d\n",1);
else fprintf(output,"%d\n",0);
}
}
fclose(input);
fclose(output);
return 0;
}