Pagini recente » Cod sursa (job #410072) | Cod sursa (job #210820) | Cod sursa (job #956800) | Cod sursa (job #1344354) | Cod sursa (job #2743517)
#include <iostream>
#include<vector>
#include<fstream>
using namespace std;
#define HASH 999983
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int N;
vector<int> LISTE[HASH]; // array of 999983 vectors
inline vector<int>::iterator Find(int x)
{
int hashPos = x % HASH;
vector<int>::iterator it;
for(it = LISTE[hashPos].begin(); it!= LISTE[hashPos].end(); it++)
if(*it == x)
return it;
return LISTE[hashPos].end();
}
inline void Insert(int x)
{
int hashPos = x % HASH;
if(Find(x) == LISTE[HASH].end())
LISTE[hashPos].push_back(x);
}
inline void Erase(int x)
{
int hashPos = x % HASH;
vector<int>::iterator it;
it = Find(x);
if(it!= LISTE[hashPos].end())
LISTE[hashPos].erase(it);
}
int main()
{
int n, op, x;
fin>>n;
for(int i = 0; i< n; i++)
{
fin>>op>>x;
if(op == 1) {Insert(x); continue;}
if(op == 2) {Erase(x);continue;}
if(op==3)
{
if(Find(x) != LISTE[x%HASH].end())
{fout<<1<<"\n";continue;}
else
{fout<<0<<"\n";continue;}
}
}
return 0;
}