Pagini recente » Cod sursa (job #2050191) | Cod sursa (job #807218) | Cod sursa (job #1728114) | Cod sursa (job #1799745) | Cod sursa (job #2821779)
#include <fstream>
#include <vector>
using namespace std;
class HashMap
{
public:
void Insert(int x)
{
int Hash = x % this->MODULO;
if (!this->Find(x))
this->resturi[Hash].emplace_back(x, 1);
}
bool Find(int x)
{
int Hash = x % this->MODULO;
for (int i = 0; i < this->resturi[Hash].size(); i++)
if (this->resturi[Hash][i].first == 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].first == x)
{
this->resturi[Hash][i].second--;
if (this->resturi[Hash][i].second == 0)
{
this->resturi[Hash][i] = this->resturi[Hash].back();
this->resturi[Hash].pop_back();
}
return;
}
}
}
private:
static const int MODULO = 666013;
vector<pair<int, int>> resturi[MODULO];
};
HashMap hm;
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)
hm.Insert(x);
else if (op == 2)
hm.Erase(x);
else
{
if (hm.Find(x))
out << 1 << '\n';
else
out << 0 << '\n';
}
}
return 0;
}