Pagini recente » Cod sursa (job #657304) | Cod sursa (job #3031451) | Cod sursa (job #2219137) | Cod sursa (job #347262) | Cod sursa (job #1438202)
#include <fstream>
#include <vector>
#define MOD 666013
using namespace std;
fstream in("hashuri.in");
ofstream out("hashuri.out");
int n, op, val;
vector<int> h[MOD];
vector<int>::iterator find_it(int key, int value)
{
for (auto it = h[key].begin(); it != h[key].end(); ++it)
{
if (*it == value)
{
return it;
}
}
return h[key].end();
}
bool find(int value)
{
int key = value % MOD;
return find_it(key, value) != h[key].end();
}
void insert(int value)
{
int key = value % MOD;
if (!find(value))
{
h[key].push_back(value);
}
}
void remove(int value)
{
int key = value % MOD;
auto pos = find_it(key, value);
if (pos != h[key].end())
{
h[key].erase(pos);
}
}
int main()
{
in >> n;
while (n--)
{
in >> op >> val;
if (op == 1)
{
insert(val);
}
else
{
if (op == 2)
{
remove(val);
}
else
{
out << find(val) << "\n";
}
}
}
in.close();
out.close();
return 0;
}