Pagini recente » Cod sursa (job #2404625) | Cod sursa (job #2227828) | Cod sursa (job #1381026) | Cod sursa (job #1730689) | Cod sursa (job #1804635)
#include <iostream>
#include <fstream>
#include <cstring>
#include <set>
#define HASH_SIZE 1000000
using namespace std;
ifstream f("hashuri.in" );
ofstream g("hashuri.out");
int hashFunction(int x) {
return x/1000000;
}
set<int> table[1000000];
void addElem(int x) {
int poz = hashFunction(x);
table[poz].insert(x);
}
void delElem(int x) {
int poz = hashFunction(x);
table[poz].erase(x);
}
bool queryElem(int x) {
int poz = hashFunction(x);
if ( table[poz].find(x) == table[poz].end() ) {
g << 0 << '\n';
return 0;
} else {
g << 1 << '\n';
return 1;
}
}
int NrOperatii;
int main()
{
f >> NrOperatii; int op, x;
for ( int i=1; i<=NrOperatii; i++ )
{
f >> op >> x;
switch ( op )
{
case 1: addElem(x); break;
case 2: delElem(x); break;
case 3: queryElem(x); break;
}
}
}