Pagini recente » Cod sursa (job #196371) | Cod sursa (job #185084) | Cod sursa (job #2780836) | Cod sursa (job #81018) | Cod sursa (job #1210430)
#include <fstream>
#include <list>
#include <algorithm>
#define M 666013
#define H(x) (x % M)
using namespace std;
list<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 list<int>;
}
list<int>* bucket = S[hx];
list<int>::iterator it = find(bucket->begin(), bucket->end(), x);
switch(op)
{
case 1:
bucket->push_back(x);
break;
case 2:
bucket->remove(x);
break;
case 3:
ofs << (it == bucket->end() ? 0 : 1) << "\n";
break;
}
}
return 0;
}