Pagini recente » Cod sursa (job #302547) | Cod sursa (job #235090) | Cod sursa (job #1572983) | Cod sursa (job #753247) | Cod sursa (job #2238639)
#include <vector>
#include <fstream>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int const BIG_PRIME = 633337;
vector<int> h[BIG_PRIME];
bool exists(int target)
{
for(int x:h[target%BIG_PRIME])
{
if(target==x)
return true;
}
return false;
}
void insert(int target)
{
if(!exists(target))
{
h[target%BIG_PRIME].push_back(target);
}
}
void erase(int target)
{
if(exists(target))
{
for(int i=0;i<h[target%BIG_PRIME].size();i++)
{
if(target==h[target%BIG_PRIME][i])
h[target%BIG_PRIME].erase(h[target%BIG_PRIME].begin()+i);
}
}
}
int main() {
int n;
f >> n;
for (int i = 0; i < n; i++) {
int op;
f >> op;
if (op == 1) {
int x;
f >> x;
insert(x);
} else if (op == 2) {
int x;
f >> x;
erase(x);
} else {
int x;
f >> x;
g << exists(x) << "\n";
}
}
}