Pagini recente » Cod sursa (job #1177209) | Cod sursa (job #2675532) | Cod sursa (job #2927724) | Cod sursa (job #749875) | Cod sursa (job #1446001)
/*
* e_030_hashuri.cpp
*
* Created on: May 31, 2015
* Author: Marius
*/
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
using namespace std;
namespace e_030_hashuri_nms
{
int N, n, m1, m2;
vector<set<int>> hash_set;
inline int hash_func1(int x)
{
return x / m1;
}
inline int hash_func2(int x)
{
int xm1 = x / m1;
return xm1 * (m2 + 1) + xm1/m2;
}
inline int hash_size1()
{
return m1 + 1;
}
inline int hash_size2()
{
return (m1 + 1) * (m2 + 1);
}
}
int main()
{
using namespace e_030_hashuri_nms;
ifstream ifs("hashuri.in");
ofstream ofs("hashuri.out");
ifs >> N;
n = 2000000000;
m1 = (int) sqrt(n) + 1;
m2 = (int) sqrt(m1) + 1;
int sz = hash_size2();
hash_set.resize(sz);
for (int i = 1; i <= N; i++)
{
int op, x;
ifs >> op >> x;
int pos = hash_func2(x); //the position in the hash_set
switch (op)
{
case 1:
hash_set[pos].insert(x);
break;
case 2:
hash_set[pos].erase(x);
break;
default:
set<int>::iterator it = hash_set[pos].find(x);
int in_set = 0;
if (it != hash_set[pos].end()) in_set = 1;
ofs << in_set << '\n';
}
}
ifs.close();
ofs.close();
return 0;
}