Pagini recente » Cod sursa (job #433039) | Cod sursa (job #1444282) | Cod sursa (job #2036293) | Cod sursa (job #926002) | Cod sursa (job #2212224)
#include<fstream>
#include<iostream>
#include<vector>
using namespace std;
#define MOD 666013
vector<int> hash[MOD];
vector<int>::iterator findValue(long long x){
int bucket=x%MOD;
vector<int>::iterator it;
for(it=hash[bucket].begin();it!=hash[bucket].end();it++)
if(*it==x) return it;
return hash[bucket].end();
}
void insert(long long x){
if(findValue(x)==hash[x%MOD].end())
hash[x%MOD].push_back(x);
}
void erase(long long x){
vector<int>::iterator it=findValue(x);
if(it!=hash[x%MOD].end())
hash[x%MOD].erase(it);
}
int main(){
ifstream in("hashuri.in");
FILE *out=fopen("hashuri.out","w");
int n; in>>n;
long long x;
short int op;
while(n--){
in>>op>>x;
if(op==1) insert(x);
if(op==2) erase(x);
if(op==3) fprintf(out,"%i\n", findValue(x)!=hash[x%MOD].end() );
}
fclose(out); in.close();
return 0;
}