Cod sursa(job #2212234)

Utilizator b10nd3Oana Mancu b10nd3 Data 13 iunie 2018 17:18:29
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include<fstream>
#include<iostream>
#include<vector>
using namespace std;

#define MOD 666013
vector<int> h[MOD];

vector<int>::iterator findValue(long long x){
	int bucket=x%MOD;
	vector<int>::iterator it;
	for(it=h[bucket].begin();it!=h[bucket].end();it++)
	   if(*it==x) return it;
	return h[bucket].end();   
}

void insert(long long x){
	if(findValue(x)==h[x%MOD].end())
	    h[x%MOD].push_back(x);
}

void erase(long long x){
	vector<int>::iterator it=findValue(x);
	int bucket=x % MOD;
	if(it!=h[bucket].end())
	   h[bucket].erase(it);
}

int main(){
	ifstream in("hashuri.in");
	FILE *out=fopen("hashuri.out","w");
	int n; in>>n;
	long long x; 
	short int op;
	while(n--){
	    in>>op>>x;
		if(op==1) insert(x);
		if(op==2) erase(x);
    	if(op==3) fprintf(out,"%i\n", findValue(x)!=h[x%MOD].end() );
	}
	fclose(out); in.close();
	return 0;
}