Cod sursa(job #573198)

Utilizator Cristy94Buleandra Cristian Cristy94 Data 5 aprilie 2011 23:47:30
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include<cstdio>
#include<vector>
#include<cmath>
#define M 999961
#define P 999979
#define Q 999983
#define cond (m[hashM] >= hashM/123457 && p[hashP] >= hashP/5672893 && q[hashQ] >= hashQ/1000003)
using namespace std;

size_t N;
size_t m[2*M],p[2*P],q[Q];

void adauga(size_t x){
	
	size_t hashM=(x+7)%M;
	size_t hashP=(x+13)%P;
	size_t hashQ=x%Q;
	
	if(!(cond))
		m[hashM]+=hashM/123456,
		p[hashP]+=hashP/567893,
		q[hashQ]+=hashQ/1000003;
}

void sterge(size_t x){
	
	size_t hashM=(x+7)%M;
	size_t hashP=(x+13)%P;
	size_t hashQ=x%Q;
	
	if(cond)
		m[hashM]-=hashM/123456,
		p[hashP]-=hashP/567893,
		q[hashQ]-=hashQ/1000003;
}
int main(){

	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	
	scanf("%d",&N);
	
	for(size_t i=1;i<=N;++i){
		
		size_t tip,x;
		
		scanf("%d%d",&tip,&x);
		
		switch(tip){
			 case 1: adauga(x);
				     break;
		     case 2: sterge(x);
				     break;
			 case 3: 
				 size_t hashM=(x+7)%M;
				 size_t hashP=(x+13)%P;
				 size_t hashQ=x%Q;
				 printf("%d\n",cond);
		}
	}
	
return 0;
}