Pagini recente » Cod sursa (job #197490) | Cod sursa (job #660349) | Cod sursa (job #2701779) | Cod sursa (job #2689574) | Cod sursa (job #2246301)
#include <cstdio>
#include <vector>
#define MAXSIZE 666013
using namespace std;
vector<vector<int>> htable(MAXSIZE);
void add_el(int x)
{
int poz = x % MAXSIZE;
htable[poz].push_back(x);
}
void del_el(int x)
{
int poz = x % MAXSIZE;
for(vector<int>::iterator it = htable[poz].begin(); it != htable[poz].end(); ++it)
if(*it == x)
{
htable[poz].erase(it);
return;
}
}
bool find_el(int x)
{
int poz = x % MAXSIZE;
for(auto it = htable[poz].begin(); it != htable[poz].end(); ++it)
if(*it == x)
return 1;
return 0;
}
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int n, i, comm, x;
scanf("%d", &n);
for(i=0; i<n; ++i)
{
scanf("%d", &comm);
switch (comm)
{
case 1:
{
scanf("%d", &x);
add_el(x);
continue;
}
case 2:
{
scanf("%d", &x);
del_el(x);
continue;
}
case 3:
{
scanf("%d", &x);
printf("%d\n", find_el(x));
}
}
}
fclose(stdin);
fclose(stdout);
return 0;
}