Pagini recente » Cod sursa (job #831315) | Cod sursa (job #2895376) | Cod sursa (job #3199397) | Cod sursa (job #3259129) | Cod sursa (job #1438639)
// Hashuri
#include <fstream>
#include <vector>
#define Key 10007
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int N;
#define x first
#define y second
template <typename T>
class Hash {
private:
std::vector< pair<T, int> > *H;
int HMAX;
std::hash<T> myhash;
public:
Hash(int hmax = 50007) {
HMAX = hmax;
H = new vector< pair<T, int> > [HMAX];
}
int& operator[](T key) {
int i = myhash(key) % HMAX;
for (typename std::vector< pair<T,int> >::iterator it = H[i].begin(); it != H[i].end(); it++) {
if (key == it->x) {
return it->y;
}
}
H[i].push_back( pair<T, int>(key, 0) );
return H[i].back().y;
}
~Hash() {
delete[] H;
}
};
Hash<int> H;
int main()
{
f>>N;
for (int i=1;i<=N;++i)
{
int tip,x;
f>>tip>>x;
if (tip==1)H[x] = 1;;
if (tip==2)H[x] = 0;
if (tip==3)g << H[x] <<'\n';
}
f.close();g.close();
return 0;
}