Pagini recente » Cod sursa (job #1035763) | Cod sursa (job #1870654) | Cod sursa (job #1999597) | Cod sursa (job #2937625) | Cod sursa (job #1249355)
#include <fstream>
#include <vector>
#define Nmax 200100
#define mod 666013
using namespace std;
class Hash {
private:
vector <int> V[mod];
int index;
void getIndex(int X) {
index = X % mod;
}
public:
Hash() {}
int search(int X) {
getIndex(X);
for(int i = 0; i < V[index].size(); i++)
if(V[index][i] == X)
return i;
return -1;
}
void insert(int X) {
if(search(X) == -1)
V[index].push_back(X);
}
void remove(int X) {
int position;
if((position = search(X)) != -1)
V[index].erase(V[index].begin() + position);
}
};
Hash hash;
int main() {
int type, x, T;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
in >> T;
while(T--) {
in >> type >> x;
switch(type) {
case 1: hash.insert(x); break;
case 2: hash.remove(x); break;
case 3: out << (hash.search(x) != -1) << '\n';
}
}
in.close();
out.close();
return 0;
}