Pagini recente » Cod sursa (job #1193135) | Cod sursa (job #1394903) | Cod sursa (job #506709) | Cod sursa (job #3207221) | Cod sursa (job #3141803)
#include<fstream>
#include <vector>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
const int dim = 666013;
vector <int> H[dim];
int hash_function(int x){
return x % dim;
}
bool cauta(int x){
int h = hash_function(x);
for (auto it:H[h])
if (it == x)
return 1;
return 0;
}
void adauga(int num){
int h = hash_function(num);
if (cauta(num) == 0)
H[h].push_back(num);
}
void sterge(int x){
int h = hash_function(x);
for (int i = 0; i < H[h].size();++i){
if (H[h][i] == x){
H[h].erase(H[h].begin() +i);
break;
}
}
}
int main(){
int op, x,q;
cin >> q;
while (q--){
cin >> op >> x;
if (op == 1)
adauga(x);
if (op == 2)
sterge(x);
if (op == 3){
cout <<cauta(x) << endl;
}
}
}