Pagini recente » Cod sursa (job #109564) | Cod sursa (job #1210224) | Cod sursa (job #2814095) | Cod sursa (job #386001) | Cod sursa (job #2617990)
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int nr = 650000;
vector <int> Hash[nr];
int Find(int x)
{
int i = x % nr;
vector <int>::iterator j;
for (j = Hash[i].begin(); j != Hash[i].end(); i++)
if (*j == x)
return 1;
return 0;
}
void Insert(int x)
{
if (Find(x) == 0)
{
int i =x%nr ;
Hash[i].push_back(x);
}
}
void Delete(int x)
{
int i = x%nr;
vector <int>::iterator j;
for (j = Hash[i].begin(); j != Hash[i].end(); i++)
{
if (*j == x)
{
break;
}
}
if (j != Hash[i].end())
Hash[i].erase(j);
}
int main() {
int N, x, y;
fin >> N;
while (N)
{
fin >> x;
if (x == 1)
{
fin >> y;
Insert(y);
}
if (x == 2)
{
fin >> y;
Delete(y);
}
if (x == 3)
{
fin >> y;
fout << Find(y) << "\n";
}
N--;
}
return 0;
}