Cod sursa(job #2901256)

Utilizator disinfoion ion disinfo Data 13 mai 2022 14:42:22
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.08 kb
#include <iostream>
#include <fstream>
#include <vector>
#define MAX 100003
using namespace std;

vector<int> hash_table[100006];

int hsh(int x){
	return x % 100003;
}

vector<int>::iterator find(int x){
	int where = hsh(x);
	vector<int>::iterator it;
	for(it=hash_table[where].begin(); it!=hash_table[where].end(); ++it)
		if(*it == x)
			return it;
	return hash_table[where].end();
}

void insert(int x){
	if(find(x) == hash_table[hsh(x)].end())
		hash_table[hsh(x)].push_back(x);
}

void erase(int x){
	vector<int>::iterator it = find(x);
	if(it != hash_table[hsh(x)].end() && !hash_table[hsh(x)].empty())
		hash_table[hsh(x)].erase(it);
}

bool query(int x){
	if(find(x) == hash_table[hsh(x)].end())
		return 0;
	else
		return 1;
}



int main(){
	ifstream fin;
	ofstream fout;
	fin.open("hashuri.in");
	fout.open("hashuri.out"); 
	int n, q, x;

	fin >> n;
	for(int i=1; i<=n; ++i){
		fin >> q >> x;
		switch(q){
			case 1:
				insert(x);
				break;
			case 2:
				erase(x);
				break;
			case 3:
				fout << query(x) << "\n";
		}

	}


}