Cod sursa(job #962829)

Utilizator Cezar_16Cezar Ghimbas Cezar_16 Data 15 iunie 2013 19:41:59
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.27 kb
#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;
}