Cod sursa(job #1573984)

Utilizator aimlockFMI Stancu Mihai aimlock Data 20 ianuarie 2016 02:18:30
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include <iostream>
#include <set>
#include <vector>
#include <fstream>
#include <stdio.h>
#define MOD 666013
using namespace std;
ifstream f("hashuri.in");

int N;
vector<int> Hash[MOD];
inline vector<int>::iterator Find_Value(int x)
{
    int poz = x % MOD;
    vector<int>::iterator it;
 
    for (it = Hash[poz].begin(); it != Hash[poz].end(); ++it)
        if (*it == x) return it;
    return Hash[poz].end();
}

inline void Insert_Value(int x)
{
    int poz = x % MOD;    
    if (Find_Value(x) == Hash[poz].end())
        Hash[poz].push_back(x);
}

inline void Erase_Value(int x)
{
    int poz = x % MOD;
    vector<int>::iterator it = Find_Value(x);
     
    if (it != Hash[poz].end())
        Hash[poz].erase(it);
}

int main(){
	 freopen("hashuri.out", "w", stdout);
	int Operation,Value;
	f>>N;
	for(int i=1;i<=N;i++){
		f>>Operation>>Value;
		if(Operation==1){
		Insert_Value(Value);
		continue;
		}
		if(Operation==2){
		Erase_Value(Value);
		continue;
		}
		printf("%d\n", Find_Value(Value) != Hash[Value % MOD].end());
	}
}