Pagini recente » Cod sursa (job #1263357) | Cod sursa (job #1952437) | Cod sursa (job #2135629) | Cod sursa (job #1139472) | Cod sursa (job #1210436)
#include <fstream>
#include <vector>
#include <algorithm>
//#define M 666013
#define M 300007
#define H(x) (x % M)
using namespace std;
vector<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 vector<int>;
}
vector<int>* bucket = S[hx];
vector<int>::iterator it = find(bucket->begin(), bucket->end(), x);
switch(op)
{
case 1:
bucket->push_back(x);
break;
case 2:
if (it != bucket->end())
{
bucket->erase(it);
}
break;
case 3:
ofs << (it == bucket->end() ? 0 : 1) << "\n";
break;
}
}
return 0;
}