Cod sursa(job #1972231)

Utilizator andreigasparoviciAndrei Gasparovici andreigasparovici Data 22 aprilie 2017 15:56:47
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.97 kb
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 1000001;
const int MOD2 = 666013;
const int MOD1 = 10007;
  
int h[MAXN];
  
bool hash_find(int nod){
    int where1 = nod % MOD1;
	int where2 = nod % MOD2;
	return h[where1]==nod || h[where2]==nod;
}
  
void hash_insert(int nod){
    int where1 = nod % MOD1;
	int where2 = nod % MOD2;
	if(!h[where1]){
		h[where1] = nod;
		return;
	}
	if(!h[where2]){
		h[where2] = nod;
		return;
	}
}
  
void hash_remove(int nod){
    int where1 = nod % MOD1;
	int where2 = nod % MOD2;

	if(h[where1] == nod){
		h[where1] = 0;
	}
	if(h[where2] == nod){
		h[where2] = 0;
	}
}
  
int q;
  
int main(){
	ifstream in("hashuri.in");  
	ofstream out("hashuri.out");
    in>>q;
    while(q--){
        int op,  param;
        in>>op>>param;
        if(op == 1){
            hash_insert(param);   
        } else if(op == 2){
            hash_remove(param);
        } else {
            out<< hash_find(param)<<'\n'; 
        }
    }
	return 0;
}