Pagini recente » Cod sursa (job #2082195) | Cod sursa (job #663661) | Cod sursa (job #1863119) | Cod sursa (job #1468556) | Cod sursa (job #1479139)
#include <fstream>
using namespace std;
#define P 3801298
#define B 28
struct HashMap {
int V[P];
void insert(int val) {
int pos = val % P;
while(V[pos]) {
if(V[pos] == val) return;
pos = pos * B % P;
}
V[pos] = val;
}
void erase(int val) {
int pos = val % P;
while(V[pos] != val) {
if(V[pos] == 0) return;
pos = pos * B % P;
}
V[pos] = -1;
}
bool find(int val) {
int pos = val % P;
while(V[pos]) {
if(V[pos] == val) return 1;
pos = pos * B % P;
}
return 0;
}
};
HashMap H;
int main() {
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int m, t, a;
fin>>m;
while(m--) {
fin>>t>>a;
if(t == 1) H.insert(a);
if(t == 2) H.erase(a);
if(t == 3) fout<<H.find(a)<<'\n';
}
return 0;
}