Cod sursa(job #1066918)

Utilizator IonMosnoiIon Mosnoi IonMosnoi Data 25 decembrie 2013 20:13:43
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include<fstream>
#include <stdio.h> 
#include<algorithm>
#include<vector>
#define mkp make_pair

#define pb push_back
using namespace std;

const int maxn = 1000;
const int M = 1000;
typedef int arrr[maxn];
arrr hash[maxn];
int nr[maxn];
  //std::vector < pair<int,int> > hash[maxn]; 

void adauga(int a){
	int x=a%M,y=a/M;
		for(int j=0;j<nr[x];j++){
		if(hash[x][j] == a/M){		
		return;
			
		}
	}
	hash[x][++nr[x]-1]=y;
}
void sterge(int a){
	int x=a%M; 
	for(int j=0;j<nr[x];j++){
		if(hash[x][j]== a/M){
			swap(hash[x][j],hash[x][--nr[x]]);
			
			//hash[a%M][j]=-1;
			break;
		}
	}
}
int check(int a){
	int x=a%M;
		for(int j=0;j<nr[x];j++){
		if(hash[x][j] == a/M){
		return 1;
			break;
		}
	}	
	return 0;
}
main(){
  ifstream fin("hashuri.in");
  ofstream fout("hashuri.out"); 
  
 int n,a,b;
 for(int i=0;i<M;nr[++i]=0);
  fin>>n;
  for(int i=1;i<=n;i++){
  	fin>>a>>b;
  	if(a==1){
  		adauga(b);
  	}else if(a==2){
  		sterge(b);
  	}else{
  		fout<<check(b)<<"\n";
  	}
  }
 
  
  
 
    fin.close(); fout.close();
  
}