Pagini recente » Cod sursa (job #3292471) | Cod sursa (job #494485) | Cod sursa (job #2739944) | Cod sursa (job #311829) | Cod sursa (job #2449944)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int Mod = 666013;
const int notFound = -1;
vector <int> H[Mod];
int n, op, x;
int hashSearch(int number);
int main()
{
fin >> n;
for (int i = 1; i <= n; ++i)
{
fin >> op >> x;
int xMod = x % Mod;
int result = hashSearch(x);
if (op == 1)
{
if (result == notFound)
{
H[xMod].push_back(x);
}
}
if (op == 2)
{
if (result != notFound)
{
swap(H[xMod][result], H[xMod][H[xMod].size() - 1]);
H[xMod].pop_back();
}
}
if (op == 3)
{
fout << (result != notFound) << '\n';
}
}
fin.close();
fout.close();
return 0;
}
int hashSearch(int number)
{
int numberMod = number % Mod;
for (int i = 0; i < H[numberMod].size(); ++i)
{
if (H[numberMod][i] == number)
{
return i;
}
}
return notFound;
}