Pagini recente » Atasamentele paginii Profil danbanica | Cod sursa (job #2291228)
#include <fstream>
#include <vector>
using namespace std;
const int MOD=666013;
int q;
vector<int> hashTable[MOD];
int findHash(int x){
int where=x%MOD;
for(auto it:hashTable[where])
if(it==x)
return 1;
return 0;
}
void insertHash(int x){
if(findHash(x))
return;
int where=x%MOD;
hashTable[where].push_back(x);
}
void removeHash(int x){
if(!findHash(x))
return;
int where=x%MOD;
vector<int>::iterator pos=hashTable[where].begin();
while(pos!=hashTable[where].end() && *pos!=x)
pos++;
hashTable[where].erase(pos);
}
int main(){
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
cin>>q;
while(q--){
int op,x;
cin>>op>>x;
if(op==1)
insertHash(x);
else if(op==2)
removeHash(x);
else
cout<<findHash(x)<<'\n';
}
return 0;
}