Pagini recente » Istoria paginii utilizator/komikaze | Cod sursa (job #3223048) | Cod sursa (job #2259040) | Cod sursa (job #1524853) | Cod sursa (job #1001838)
#include <iostream>
#include <fstream>
using namespace std;
#define N 1000000
#define P 17
int p[N/P+1] = {0};
int hash(int x, bool t) {
if(t) return x/P;
return x%P;
}
void in(int x) {
p[hash(x,1)] *= P+1;
p[hash(x,1)] += hash(x,0);
}
void out(int x) {
int num[18];
int aux = p[hash(x,1)], i = 0;
while(aux!=0) {
num[++i] = aux%(P+1);
aux /= P+1;
}
p[hash(x,1)] = 0;
for(int k=1;k<=i;k++) {
if(num[k]==hash(x,0)) continue;
p[hash(num[k],1)] *= P+1;
p[hash(num[k],1)] += hash(num[k],0);
}
}
bool look(int x) {
bool ok = false;
int aux = p[hash(x,1)];
while(aux!=0) {
if(aux%(P+1)==hash(x,0)) {ok = true;break;}
aux /= P+1;
}
return ok;
}
int main() {
ifstream f("hashuri.in");
ofstream fout("hashuri.out");
int n, o, p;
f>>n;
while(n-->0) {
f>>o>>p;
switch(o) {
case 1: in(p); break;
case 2: out(p); break;
case 3: fout<<look(p)<<endl; break;
}
}
return 0;
}