Pagini recente » Cod sursa (job #1642828) | Cod sursa (job #624584) | Cod sursa (job #2364717) | Cod sursa (job #395182) | Cod sursa (job #1090874)
// Include
#include <fstream>
#include <vector>
using namespace std;
// Definitii
#define pb push_back
// Constante
const int mod = 666013;
// Functii
void hashInsert(int val);
void hashDelete(int val);
int hashQuery(int val);
// Variabile
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int questions;
int type, val;
vector<int> HASH[mod];
// Main
int main()
{
in >> questions;
while(questions--)
{
in >> type >> val;
switch(type)
{
case 1: { hashInsert(val); break; }
case 2: { hashDelete(val); break; }
case 3: { out << hashQuery(val) << '\n'; }
}
}
in.close();
out.close();
return 0;
}
void hashInsert(int val)
{
int pos = val % mod;
vector<int>::iterator it, end=HASH[pos].end();
for(it=HASH[pos].begin() ; it!=end ; ++it)
if(*it == val)
return;
HASH[pos].pb(val);
}
void hashDelete(int val)
{
int pos = val % mod;
vector<int>::iterator it, end=HASH[pos].end();
for(it=HASH[pos].begin() ; it!=end ; ++it)
{
if(*it == val)
{
HASH[pos].erase(it);
return;
}
}
}
int hashQuery(int val)
{
int pos = val % mod;
vector<int>::iterator it, end=HASH[pos].end();
for(it=HASH[pos].begin() ; it!=end ; ++it)
if(*it == val)
return 1;
return 0;
}