Pagini recente » Cod sursa (job #1789361) | Cod sursa (job #3324888) | Cod sursa (job #2291782) | Cod sursa (job #1413329) | Cod sursa (job #3310724)
/*
https://infoarena.ro/problema/hashuri
*/
#include <fstream>
using namespace std;
const int N = 1e6;
const int M = 666019;
const int NIL = -1;
struct nod
{
int info;
int urm;
};
nod v_nod[N];
int lst[M], n_v_nod;
void init_liste()
{
for (int i = 0; i < M; i++)
{
lst[i] = NIL;
}
}
bool exista(int val)
{
int c = val % M;
int p = lst[c];
while (p != NIL)
{
if (v_nod[p].info == val)
{
return true;
}
p = v_nod[p].urm;
}
return false;
}
void adauga(int val)
{
if (exista(val))
{
return;
}
v_nod[n_v_nod].info = val;
int c = val % M;
v_nod[n_v_nod].urm = lst[c];
lst[c] = n_v_nod++;
}
void sterge(int val)
{
if (!exista(val))
{
return;
}
int c = val % M;
int p = lst[c];
while (v_nod[p].info != val)
{
p = v_nod[p].urm;
}
v_nod[p].info = v_nod[lst[c]].info;
lst[c] = v_nod[lst[c]].urm;
}
int main()
{
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int n;
init_liste();
in >> n;
for (int i = 0; i < n; i++)
{
int tip, val;
in >> tip >> val;
if (tip == 1)
{
adauga(val);
}
else if (tip == 2)
{
sterge(val);
}
else
{
out << exista(val) << "\n";
}
}
in.close();
out.close();
return 0;
}