Pagini recente » Profil PetrusSerban | Cod sursa (job #2176463) | Cod sursa (job #1834880) | Cod sursa (job #811318) | Cod sursa (job #1996140)
#include <fstream>
#include <vector>
#define M 666013
using namespace std;
vector<int> v[666100];
int m;
int hsh(int x)
{
double y = 0.618033;
double xy = (double)x * y;
xy -= (int) xy;
double ans = xy * M;
return (int) ans;
}
int find_val(int x)
{
int lst = hsh(x);
for (unsigned i = 0; i < v[lst].size(); ++i)
if(v[lst][i] == x)
return i;
return v[lst].size();
}
void insert_val(int x)
{
int lst = hsh(x);
if(find_val(x) == (int)v[lst].size())
v[lst].push_back(x);
}
void erase_val (int x)
{
int lst = hsh(x);
if(find_val(x) != (int)v[lst].size())
v[lst].erase(v[lst].begin()+find_val(x));
}
int main()
{
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
fin >> m;
while(m--){
int test, x;
fin >> test >> x;
switch(test){
case 1:
insert_val(x);
break;
case 2:
erase_val(x);
break;
case 3:
fout << (find_val(x) != (int)v[hsh(x)].size()) << "\n";
break;
}
}
fin.close();
fout.close();
return 0;
}