Pagini recente » Cod sursa (job #2822030) | Cod sursa (job #947735) | Cod sursa (job #2454010) | Cod sursa (job #1665597) | Cod sursa (job #1210411)
#include <fstream>
#include <set>
#define M 666013
#define H(x) (x % M)
using namespace std;
set<int>* S[M];
ifstream ifs("hashuri.in");
ofstream ofs("hashuri.out");
int main()
{
int n;
ifs >> n;
for (int i = 1; i <= n; ++i)
{
int op, x;
ifs >> op >> x;
// Determine the bucket
int hx = H(x);
if (S[hx] == NULL)
{
S[hx] = new set<int>;
}
set<int>* bucket = S[hx];
set<int>::iterator it = bucket->find(x);
switch(op)
{
case 1:
bucket->insert(x);
break;
case 2:
bucket->erase(x);
break;
case 3:
ofs << (it == bucket->end() ? 0 : 1) << "\n";
break;
}
}
return 0;
}