Pagini recente » Cod sursa (job #1470869) | Cod sursa (job #1453971) | Cod sursa (job #320883) | Cod sursa (job #2471297) | Cod sursa (job #803995)
Cod sursa(job #803995)
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;
int hash_n;
vector<vector<int> > v;
void add_item(int x)
{
for (int i=0; i<v[x%hash_n].size(); i++)
if (v[x%hash_n][i]==x) return;
v[x%hash_n].push_back(x);
}
void remove_item(int x)
{
for (int i=0; i<v[x%hash_n].size(); i++)
if (v[x%hash_n][i]==x) {
v[x%hash_n].erase(v[x%hash_n].begin() + i);
return;
}
}
bool find(int x)
{
for (int i=0; i<v[x%hash_n].size(); i++)
if (v[x%hash_n][i]==x) return true;
return false;
}
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)==true) g<<1<<'\n';
else g<<0<<'\n';
}
f.close();
g.close();
return 0;
}