Pagini recente » Cod sursa (job #1258340) | Cod sursa (job #407898) | Cod sursa (job #796688) | Cod sursa (job #1446444) | Cod sursa (job #962829)
Cod sursa(job #962829)
#include<iostream>
#include<stdio.h>
using namespace std;
#define n1 900000000
#define n2 200000001
void insert(long nr,bool *&hash1,bool *&hash2,bool *&hash3) {
if(nr > n1 && nr <= n1+n2)
hash2[nr-n1] = true;
else if(nr > n1+n2)
hash3[nr - (n1+n2+1)] = true;
else
hash1[nr] = true;
}
void erase(long nr,bool *&hash1,bool *&hash2,bool *&hash3) {
if(nr > n1 && nr <= n1+n2)
hash2[nr-n1] = false;
else if(nr > n1+n2)
hash3[nr - (n1+n2+1)] = false;
else
hash1[nr] = false;
}
void display(long nr,bool *&hash1,bool *&hash2,bool *&hash3, FILE *out) {
if(nr > n1 && nr <= n1+n2)
fprintf(out, "%d\n", hash2[nr-n1]);
else if(nr > n1+n2)
fprintf(out, "%d\n", hash3[nr - (n1+n2+1)]);
else
fprintf(out, "%d\n", hash1[nr]);
}
int main()
{
FILE *in, *out;
bool *hash1, *hash2, *hash3;
int op;
long x;
int n;
hash1 = new bool[n1];
hash2 = new bool[n1];
hash3 = new bool[n2];
in = fopen("hashuri.in","r");
out = fopen("hashuri.out","w");
fscanf(in,"%d", &n);
for(long long i = 0; i < n; i++) {
fscanf(in, "%d", &op);
fscanf(in, "%ld", &x);
if(op == 1)
insert(x,hash1,hash2,hash3);
else if(op == 2)
erase(x,hash1,hash2,hash3);
else
display(x,hash1,hash2,hash3,out);
}
delete[] hash2;
delete[] hash1;
delete[] hash3;
return 0;
}