Pagini recente » Cod sursa (job #80944) | Cod sursa (job #1661435) | Cod sursa (job #1098693) | Votati personajul preferat Infoarena | Cod sursa (job #1139025)
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iterator>
#include <random>
#include <assert.h>
using namespace std;
const string file = "hashuri";
const string infile = file + ".in";
const string outfile = file + ".out";
const int INF = 0x3f3f3f3f;
const int MODN = 66697;
vector<int> H[MODN];
int cHash(int x)
{
return x % MODN;
}
void insert(int x)
{
int h = cHash(x);
bool found = false;
for(vector<int>::iterator itr = H[h].begin();
itr != H[h].end();
itr++)
{
if(*itr == x)
{
found = true;
break;
}
}
if(found == false)
H[h].push_back(x);
}
void remove(int x)
{
int h = cHash(x);
bool found = false;
vector<int>::iterator jtr;
for(vector<int>::iterator itr = H[h].begin();
itr != H[h].end();
itr++)
{
if(*itr == x)
{
found = true;
jtr = itr;
}
}
if(found)
{
iter_swap(H[h].end() - 1, jtr);
H[h].pop_back();
}
}
bool exists(int x)
{
int h = cHash(x);
bool found = false;
for(vector<int>::iterator itr = H[h].begin();
itr != H[h].end();
itr++)
{
if(*itr == x)
{
found = true;
break;
}
}
return found;
}
//#define ONLINE_JUDGE
int main()
{
#ifdef ONLINE_JUDGE
ostream &fout = cout;
istream &fin = cin;
#else
fstream fin(infile.c_str(), ios::in);
fstream fout(outfile.c_str(), ios::out);
#endif
int N;
fin >> N;
for(int i = 0; i < N; i++)
{
int op, x;
fin >> op >> x;
if(op == 1)
{
insert(x);
}
else if(op == 2)
{
remove(x);
}
else if(op == 3)
{
fout << (exists(x) == true ? 1 : 0 ) << "\n";
}
}
#ifdef ONLINE_JUDGE
#else
fout.close();
fin.close();
#endif
}