Pagini recente » Cod sursa (job #49562) | Cod sursa (job #668411) | Cod sursa (job #258455) | Cod sursa (job #213295) | Cod sursa (job #2445621)
#include <bits/stdc++.h>
#define maxN 1000002
#define m 1543
using namespace std;
FILE *fin = freopen("hashuri.in", "r", stdin);
FILE *fout = freopen("hashuri.out", "w", stdout);
int n, r = 3, A[4];
class Hahs
{
public :
vector < int > L[m];
int Key(int x)
{
int cp = x, K = 0;
for (int i = 0; i < r; ++ i, cp /= m)
K = (1LL * A[i] * (cp % m) + K) % m;
return K;
}
void Insert(int x)
{
int k = Key(x);
bool found = false;
for (auto it : L[k])
if (it == x)
{
found = true;
break;
}
if (!found)
L[k].push_back(x);
}
void Delete(int x)
{
int k = Key(x);
int sz = L[k].size();
bool found = false;
for (int i = 0; i < sz; ++ i)
if (L[k][i] == x)
{
found = true;
swap(L[k].back(), L[k][i]);
}
if (found)
L[k].pop_back();
}
bool Search(int x)
{
int k = Key(x);
for (auto it : L[k])
if (it == x)
return true;
return false;
}
} H;
int main()
{
scanf("%d", &n);
srand(time(0));
int a = rand();
int cp = a;
for (int i = 0; i < r; ++ i, cp /= m)
A[i] = cp % m;
while (n --)
{
int ty, x;
scanf("%d%d", &ty, &x);
if (ty == 1)
H.Insert(x);
else if (ty == 2)
H.Delete(x);
else
printf("%d\n", H.Search(x));
}
return 0;
}