Pagini recente » Cod sursa (job #159226) | Cod sursa (job #459731) | Cod sursa (job #306754) | Cod sursa (job #738020) | Cod sursa (job #832306)
Cod sursa(job #832306)
///timing 11:53
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in ("hashuri.in");
ofstream out ("hashuri.out");
int value;
class hash {
int Key;
vector <int> * H;
vector<int>::iterator it;
public:
hash() { Key = 0; H = new vector<int>[1]; };
hash(int);
void insert();
void erase();
int check();
};
hash :: hash(int K){
Key = K;
H = new vector <int> [K];
}
void hash :: insert () {
int X = value % Key;
H[X].push_back(value);
}
void hash :: erase () {
int X = value % Key;
for(it = H[X].begin(); it != H[X].end(); it++)
if(*it == value){
H[X].erase(it);
break;
}
}
int hash :: check() {
int X = value % Key;
for(it = H[X].begin(); it != H[X].end(); it++)
if(*it == value) return 1;
return 0;
}
int main()
{
hash A(666013);
int N, operation;
in >> N;
while(N--){
in >> operation >> value;
switch (operation) {
case 1: A.insert(); break;
case 2: A.erase(); break;
case 3: out << A.check() << "\n"; break;
}
}
return 0;
}