Pagini recente » Cod sursa (job #2258761) | Cod sursa (job #3030215) | Cod sursa (job #2129464) | Cod sursa (job #2494891) | Cod sursa (job #2205464)
#include <iostream>
#include <vector>
#include <fstream>
#define mod 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector <int> V[mod];
int operations;
int H(int x)
{
return x % mod;
}
void add(int key)
{
int ind = H(key);
for (int i = 0; i < V[ind].size(); ++i)
if (V[ind][i] == key)
return;
V[ind].push_back(key);
}
void del(int key)
{
int ind = H(key);
for (int i = 0; i < V[ind].size(); ++i)
if (V[ind][i] == key)
{
V[ind].erase(V[ind].begin() + i);
return;
}
}
bool is(int key)
{
int ind = H(key);
for (int i = 0; i < V[ind].size(); ++i)
if (V[ind][i] == key)
return true;
return false;
}
void computeOperation(int op, int key)
{
if (op == 1)
add(key);
else if (op == 2)
del(key);
else
if (is(key))
g<<1<<endl;
else
g<<0<<endl;
}
int main()
{
f>>operations;
int op, key;
for (int i = 0; i < operations; ++i)
{
f>>op>>key;
computeOperation(op, key);
}
return 0;
}