Pagini recente » Cod sursa (job #2753130) | Cod sursa (job #1944551) | Cod sursa (job #1935281) | Cod sursa (job #3140768) | Cod sursa (job #1248120)
/// Craciun Catalin
/// Hashuri
#include <iostream>
#include <fstream>
#include <vector>
#define MOD 700001
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
class Hash{
public:
bool elementExists(int x) {
int line = x%MOD;
if (iteratorFor(x) != H[line].end())
return true;
return false;
}
void addElement(int x) {
int line = x%MOD;
if (iteratorFor(x) == H[line].end())
H[line].push_back(x);
}
void eraseElement(int x) {
int line = x%MOD;
vector<int>::iterator it = iteratorFor(x);
if (it != H[line].end()) {
H[line].erase(it);
}
}
private:
vector<int> H[MOD];
vector<int>::iterator iteratorFor(int x) {
int line = x%MOD;
for (vector<int>::iterator it = H[line].begin(); it != H[line].end(); ++it) {
if (*it == x)
return it;
}
return H[line].end();
}
};
int n;
Hash *customHash;
int main() {
customHash = new Hash();
f>>n;
for (int i=1;i<=n;i++) {
int type, x;
f>>type>>x;
if (type == 1) {
customHash->addElement(x);
} else if (type == 2) {
customHash->eraseElement(x);
} else if (type == 3) {
g<<customHash->elementExists(x)<<'\n';
}
}
f.close(); g.close();
return 0;
}