Pagini recente » Cod sursa (job #2297126) | Cod sursa (job #2720340) | Cod sursa (job #1177244) | Cod sursa (job #63480) | Cod sursa (job #1197008)
/* vector STL */
/*using namespace std;
#include <fstream>
#include <vector>
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int Nmax = 1000000;
const int P = 666013;
vector<int> L[P];
void push(int) ;
void sterge(int) ;
bool search1(int) ;
int main()
{
int i, a, tip, n;
fin>>n;
for(i=0; i<n; ++i)
{
fin>>tip>>a;
if(tip==1) push(a);
if(tip==2) sterge(a);
if(tip==3) fout<<search1(a)<<'\n';
}
return 0;
}
void push(int x)
{
int hash = x%P;
for(vector<int>::iterator it = L[hash].begin(); it!=L[hash].end(); ++it)
if(*it == x) return;
L[hash].push_back(x);
}
void sterge(int x)
{
int hash = x%P;
for(vector<int>::iterator it = L[hash].begin(); it!=L[hash].end(); ++it)
if(*it == x)
{
L[hash].erase(it);
return;
}
}
bool search1(int x)
{
int hash = x%P;
for(vector<int>::iterator it = L[hash].begin(); it!=L[hash].end(); ++it)
if(*it == x) return 1;
return 0;
}
*/
/* liste simplu inlantuite */
/*using namespace std;
#include <fstream>
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int Nmax = 1000000;
const int P = 666013;
struct _nod {int x; nod* urm;} ;
_nod* prim[P];
void push(int) ;
void sterge(int) ;
bool search1(int) ;
int main()
{
int i, a, tip, n;
for(i=0; i<P; ++i) prim[i]->urm = NULL; prim[i]->x = 0;
fin>>n;
for(i=0; i<n; ++i)
{
fin>>tip>>a;
if(tip==1) push(a);
if(tip==2) sterge(a);
if(tip==3) fout<<search1(a)<<'\n';
}
return 0;
}
void push(int x)
{
int hash = x%P;
if(prim[hash]->x == 0) {prim[hash]->x = x; return;}
for(_nod *it = prim[hash]; it->urm != NULL; it = it->urm)
if(it->x == x) return;
if(it->x == x) return;
_nod *nou = new _nod;
it->urm = nou; nou->urm = NULL;
nou->x = x;
}
void sterge(int x)
{
int hash = x%P;
for(_nod *it = prim[hash]; it != NULL; it = it->urm)
if(*it == x)
{
L[hash].erase(it);
return;
}
}
bool search1(int x)
{
int hash = x%P;
for(_nod *it = prim[hash]; it != NULL; it = it->urm)
if(it->x == x) return 1;
return 0;
}
*/
/*doua tabele de has*/
using namespace std;
#include <fstream>
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int Nmax = 1000000;
const int P1 = 666013;
const int P2 = 100003;
int hash1[P1], hash2[P2];
void push(int) ;
void sterge(int) ;
bool search1(int) ;
int main()
{
int i, a, tip, n;
fin>>n;
for(i=0; i<n; ++i)
{
fin>>tip>>a;
if(tip==1) push(a);
if(tip==2) sterge(a);
if(tip==3) fout<<search1(a)<<'\n';
}
return 0;
}
void push(int a)
{
if(hash1[a%P1] && hash2[a%P2])
return;
++hash1[a%P1];
++hash2[a%P2];
}
void sterge(int a)
{
if(!hash1[a%P1] || !hash2[a%P2])
return;
--hash1[a%P1];
--hash2[a%P2];
}
bool search1(int a)
{
return (hash1[a%P1] && hash2[a%P2]);
}