Pagini recente » Cod sursa (job #2425920) | Cod sursa (job #674625) | Cod sursa (job #2315990) | Cod sursa (job #1466871) | Cod sursa (job #1908192)
#include<fstream>
#include<iostream>
#include<vector>
#define MOD 123457
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
int N;
vector <int> L[1000005];
inline int Cauta_element(int x)
{
int R, j, gasit=0;
R=x%MOD;
for (j=0; j<L[R].size() && !gasit; j++)
if (L[R][j] == x) gasit=1;
if (!gasit) return 0;
return 1;
}
void Adauga_element(int x)
{
int R;
if (Cauta_element(x)==0) /// nu apare
{ R=x%MOD;
L[R].push_back(x);
}
}
void Sterge_element(int x)
{
int R, j, gasit=0;
if (Cauta_element(x)==1) /// am ce sterge
{ R=x%MOD;
for (j=0; j<L[R].size()&& !gasit; j++)
{
if (L[R][j] == x)
{
L[R][j] = L[R][L[R].size()-1];
L[R].pop_back();
gasit = 1;
}
}
}
}
int main ()
{
int i, x, q;
fin >> N;
for (i=1; i<=N; i++)
{
fin >> q >> x;
/// cout << q << " " << x;
if (q==1) Adauga_element(x);
else if (q==2) Sterge_element(x);
else fout << Cauta_element(x) << "\n";
}
fin.close();
fout.close();
return 0;
}