Pagini recente » Cod sursa (job #3164543) | Cod sursa (job #2958048) | Cod sursa (job #2869397) | Cod sursa (job #2990499) | Cod sursa (job #804005)
Cod sursa(job #804005)
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;
int hash_n;
vector<vector<int> > v;
int find(int x)
{
for (int i=0; i<v[x%hash_n].size(); i++)
if (v[x%hash_n][i]==x) return i;
return -1;
}
void add_item(int x)
{
if (find(x)==-1) v[x%hash_n].push_back(x);
}
void remove_item(int x)
{
int aux=find(x);
if (aux!=-1) v[x%hash_n].erase(v[x%hash_n].begin() + aux);
}
void create_vector(int n)
{
hash_n=sqrt((float)n)*log2(n);
v.resize(hash_n);
for (int i=0; i<v.size(); i++)
v[i]=vector<int>();
}
int main()
{
int i,n;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
f>>n;
create_vector(n);
int x;
int oper;
for (i=0; i<n; i++) {
f>>oper>>x;
if (oper==1) add_item(x);
else if (oper==2) remove_item(x);
else if (oper==3 && find(x)!= -1) g<<1<<'\n';
else g<<0<<'\n';
}
f.close();
g.close();
return 0;
}