Pagini recente » Cod sursa (job #721267) | Cod sursa (job #247593) | Cod sursa (job #2643964) | Cod sursa (job #525896) | Cod sursa (job #2642965)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int PRIME = 101'839;
int n, type, nr;
vector < int > set[PRIME];
vector<int>::iterator Find(const int& value) {
const int Hash = value % PRIME;
for(vector<int>::iterator it = set[Hash].begin(); it != set[Hash].end();++it)
if(*it == value)
return it;
return set[Hash].end();
}
void Insert(const int& value) {
const int Hash = value % PRIME;
if(Find(value) == set[Hash].end())
set[Hash].push_back(value);
}
void Erase(const int& value) {
const int Hash = value % PRIME;
auto it = Find(value);
if(it != set[Hash].end())
set[Hash].erase(it);
}
int main() {
f >> n;
while(n--) {
f >> type >> nr;
if(type == 1)
Insert(nr);
else if(type == 2)
Erase(nr);
else
g << (Find(nr) != set[ nr % PRIME ].end()) << '\n';
}
return 0;
}