Pagini recente » Cod sursa (job #2343996) | Cod sursa (job #2658418)
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
// 1017932
const int MOD = 666013;
vector <int> v[MOD];
unsigned int I;
int find_hash(int x) {
int cod=x%MOD;
unsigned int i=0;
while(i<v[cod].size() && v[cod][i]!=x)
i++;
I=i; // not perfect but i found a solution
return i<v[cod].size();
}
void add_hash(int x) {
if(!find_hash(x)) {
int cod=x%MOD;
v[cod].push_back(x);
}
}
void del_hash(int x) {
if(find_hash(x)) {
int cod=x%MOD;
v[cod].erase(v[cod].begin()+I);
}
}
int main() {
FILE *fin,*fout;
int n,i,tip,x;
fin=fopen("hashuri.in","r");
fout=fopen("hashuri.out","w");
fscanf(fin,"%d",&n);
for(i=0;i<n;i++) {
fscanf(fin,"%d%d",&tip,&x);
if(tip==1)
add_hash(x);
else if(tip==2)
del_hash(x);
else
fprintf(fout,"%d\n",find_hash(x));
}
fclose(fin);
fclose(fout);
return 0;
}