Pagini recente » Cod sursa (job #143357) | Cod sursa (job #1358040) | Cod sursa (job #1568130) | Cod sursa (job #2819525) | Cod sursa (job #714744)
Cod sursa(job #714744)
#include <cstdio>
#include <vector>
using namespace std;
#define file_in "hashuri.in"
#define file_out "hashuri.out"
#define mod 666013
class Hash{
private:
vector<int> H[mod+20];
public:
int cauta(int nod);
void adauga(int nod);
void sterge(int nod);
};
Hash h ;
int Hash::cauta(int nod){
int k=nod%mod;
vector<int> :: iterator it;
for (it=h.H[k].begin();it!=h.H[k].end();++it)
if (*it==nod)
return 1;
return 0;
}
void Hash::adauga(int nod){
int k=nod%mod;
h.H[k].push_back(nod);
}
void Hash::sterge(int nod){
int k=nod%mod;
vector<int> :: iterator it;
for (it=h.H[k].begin();it!=h.H[k].end();++it)
if (*it==nod){
h.H[k].erase(it);
break;
}
}
int main(){
int Q,X,Tip;
freopen(file_in,"r",stdin);
freopen(file_out,"w",stdout);
scanf("%d", &Q);
while(Q--){
scanf("%d %d", &Tip, &X);
if (Tip==1){
if (!h.cauta(X))
h.adauga(X);
}
else
if (Tip==2){
if (h.cauta(X))
h.sterge(X);
}
else
printf("%d\n", h.cauta(X));
}
return 0;
}