Cod sursa(job #2619579)

Utilizator paulvlad43Vlad Paul Munteanu paulvlad43 Data 28 mai 2020 00:12:46
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.01 kb
#include<iostream>
#include<bits/stdc++.h>
#include <fstream>
#include<unordered_map>
#include <queue>
using namespace std;
const int n=2000000;

ifstream f("hashuri.in");
ofstream f1("hashuri.out");
	
class Hash{
	public:
		vector<vector<int>>h;
		Hash(){
			h.resize(n);
			}
		void tip1(int x);
		void tip2(int x);
		void tip3(int x);
};

void Hash::tip1(int x){
		h[x%n].push_back(x);
}
void Hash::tip2(int x){
	int i=0;
	for(auto & val :h[x%n]){
		if (val==x)
			h[x%n].erase(h[x%n].begin()+i);
		i++;
	}
}
void Hash::tip3(int x){
	int gasit=0;
	for (auto &val:h[x%n]){
		if (val==x)
			gasit=1;
	}
	
	if (gasit==1){
		
		 f1<<1<<"\n";
		 cout<<1<<endl;
	}
	else{
		f1<<0<<"\n";
		cout<<0<<endl;
	}
}




int main(){
	
	Hash * hash =new Hash();

	
	int nr,a,b;
	f>>nr;
	for (int i=0;i<nr;i++){
		f>>a>>b;
		if (a==1){
			hash->tip1(b);
			
		}
		else if (a==2){
			hash->tip2(b);
		}
		else if (a==3){
			hash->tip3(b);
		}
	}
	
	
	
	return 0;
	
}