Pagini recente » Cod sursa (job #901310) | Cod sursa (job #1970932) | Cod sursa (job #3293616) | Cod sursa (job #1161877) | Cod sursa (job #1093293)
#include <fstream>
using namespace std;
#define NIL 0
#define DELETED -1
template<const int Size, const int mod>
class HashTable{
int table[Size], pos, inc;
void lookup(int x){
pos = x % Size;
inc = 1 + x % mod;
while (table[pos] != x && table[pos] != NIL){
pos += inc;
if (Size <= pos) pos -= Size;
}
}
public:
void insert(int x){
lookup(x);
table[pos] = x;
}
void erase(int x){
lookup(x);
if (table[pos] == x) table[pos] = DELETED;
}
bool find(int x){
lookup(x);
return table[pos] == x;
}
};
HashTable<1046527, 998077> H;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int main(){
int nrE, type, x;
in >> nrE;
while (nrE--){
in >> type >> x;
if (type == 1) H.insert(x);
if (type == 2) H.erase(x);
if (type == 3) out << H.find(x) << "\n";
}
return 0;
}