Pagini recente » Cod sursa (job #2029541) | Cod sursa (job #322047) | Cod sursa (job #612093) | Rating Calota Stefan (fanevoda) | Cod sursa (job #972129)
Cod sursa(job #972129)
#include <fstream>
#include <vector>
#include <set>
using namespace std;
const int inf = 0x3f3f3f3f;
template<const int Size>
class HashTable{
int hash[Size];
inline bool keepGoing(int poz, int val){
return hash[poz] && hash[poz] != val;
}
int supposedPosition(int val){
int poz = 0;
while ( keepGoing( (val + poz * poz) % Size), val )
++poz;
return (val + poz * poz) % Size;
}
public:
HashTable(){
memset(hash, 0, sizeof(hash));
}
bool find(int val){
return hash[ supposedPosition(val) ] == val;
}
void insert(int val){
hash[ supposedPosition(val) ] = val;
}
void erase(int val){
int poz = supposedPosition(val);
if (hash[poz] == val)
hash[poz] = inf;
}
};
HashTable<3036643> H;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int main(){
int times, tip, x;
in >> times;
while (times--){
in >> tip >> x;
if (tip == 1)
H.insert(x);
if (tip == 2)
H.erase(x);
if (tip == 3)
out << H.find(x) << "\n";
}
return 0;
}