Pagini recente » Cod sursa (job #521263) | Cod sursa (job #1558628) | Cod sursa (job #741626) | Cod sursa (job #1612175) | Cod sursa (job #1043260)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n;
const int mod = 666013;
vector<int> G[mod];
void Erase(const int nr)
{
int poz = nr % mod;
int lpoz = G[poz].size()-1;
for (unsigned int i = 0; i < G[poz].size(); ++i)
if ( G[poz][i] == nr )
{
swap(G[poz][i], G[poz][lpoz]); // swap found element with last element and
G[poz].pop_back(); // pop
return;
}
}
bool Find(const int nr)
{
int poz = nr % mod;
vector<int>::iterator it;
for (it = G[poz].begin(); it != G[poz].end(); ++it)
if ( *it == nr ) return true;
return false;
}
void Insert(const int nr)
{
if ( !Find(nr) ) return;
int poz = nr % mod;
G[poz].push_back(nr);
}
int main()
{
fin >> n;
int op, nr;
for(int i = 0; i < n; ++i)
{
fin >> op >> nr;
if ( op == 1 ) Insert(nr);
if ( op == 2 ) Erase(nr);
if ( op == 3 ) cout << Find(nr) << '\n';
}
cout << '\n';
fin.close();
fout.close();
return 0;
}