Pagini recente » Cod sursa (job #2153491) | Cod sursa (job #208670) | Cod sursa (job #2324508) | Cod sursa (job #1585031) | Cod sursa (job #2794750)
#include <fstream>
#include <vector>
using namespace std;
class HashSet
{
public:
void Insert(int x)
{
int Hash = x % this->MODULO;
if (!this->Find(x))
this->resturi[Hash].push_back(x);
}
bool Find(int x)
{
int Hash = x % this->MODULO;
for (int i = 0; i < this->resturi[Hash].size(); i++)
if (this->resturi[Hash][i] == x)
return true;
return false;
}
void Erase(int x)
{
int Hash = x % this->MODULO;
for (int i = 0; i < this->resturi[Hash].size(); i++)
{
if (this->resturi[Hash][i] == x)
{
this->resturi[Hash][i] = this->resturi[Hash].back();
this->resturi[Hash].pop_back();
return;
}
}
}
private:
static const int MODULO = 666013;
vector<int> resturi[MODULO];
};
HashSet hs;
int main()
{
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int n;
in >> n;
for (int i = 1; i <= n; i++)
{
int op, x;
in >> op >> x;
if (op == 1)
hs.Insert(x);
else if (op == 2)
hs.Erase(x);
else
{
if (hs.Find(x))
out << 1 << '\n';
else
out << 0 << '\n';
}
}
return 0;
}