Cod sursa(job #1066890)

Utilizator IonMosnoiIon Mosnoi IonMosnoi Data 25 decembrie 2013 19:19:48
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 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;

  std::vector < pair<int,int> > hash[maxn]; 

void adauga(int a){
	int x=a%M,y=a/M;
		for(int j=0;j<hash[x].size();j++){
		if(hash[x][j].first == a/M){		
		return;
			
		}
	}
	hash[x].pb(mkp(y,0));
}
void sterge(int a){
	int x=a%M; 
	for(int j=0;j<hash[x].size();j++){
		if(hash[x][j].first == a/M){
			swap(hash[x][j],hash[x][hash[x].size()-1]);
			hash[x].pop_back();
			//hash[a%M][j]=-1;
			break;
		}
	}
}
int check(int a){
	int x=a%M;
		for(int j=0;j<hash[x].size();j++){
		if(hash[x][j].first == a/M){
		return 1;
			break;
		}
	}	
	return 0;
}
main(){
  ifstream fin("hashuri.in");
  ofstream fout("hashuri.out"); 
  
 int n,a,b;

  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();
  
}