Pagini recente » Cod sursa (job #3199988) | Cod sursa (job #1392619) | Cod sursa (job #273163) | Cod sursa (job #314433) | Cod sursa (job #2623010)
#include <iostream>
#include <fstream>
#include <vector>
#define modulo 66013
using namespace std;
class Hash{
vector<int> el[modulo];
static int get_m(int x){
return x%modulo;
}
public:
void insert(int x){
el[get_m(x)].push_back(x);
}
void remove(int x){
int m = get_m(x);
for(int i=0;i<el[m].size();i++)
if(el[m][i]==x)
el[m].erase(el[m].begin()+i);
}
bool contains(int x){
int m = get_m(x);
for(int i : el[m])
if(i==x)
return true;
return false;
}
};
int main() {
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n, op, x;
Hash* hash = new Hash();
fin>>n;
while(n--){
fin>>op>>x;
if(op==1){
hash->insert(x);
continue;
}
if(op==2){
hash->remove(x);
continue;
}
fout<<(hash->contains(x))<<'\n';
}
delete hash;
fin.close();
fout.close();
return 0;
}