Cod sursa(job #1041919)
Utilizator | Data | 26 noiembrie 2013 13:07:53 | |
---|---|---|---|
Problema | Hashuri | Scor | 40 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 3.56 kb |
#include <iostream>
//#include <unordered_map>
#include <algorithm>
#include <fstream>
std::ifstream fin("hashuri.in");
std::ofstream fout("hashuri.out");
struct nod
{
int val;
nod *next;
};
int n;
//std::unordered_map<int, bool> hashu;
nod *prim[666014];// = new nod;
void citire()
{
// nod *ultim;// = prim;
// prim->next = NULL;
int x, y;
fin>>n;
for(int i = 0; i < n; i++)
{
fin>>x>>y;
if(x == 1)
{
//hashu[y] = 1;
if(prim[y%666013])
{
nod *val = prim[y%666013];
bool found = false;
while(val)
{
// std::cout<<val->val<<'\n';
if(val->val == y)
{
found = true;
break;
}
val = val->next;
}
val = NULL;
if(!found)
{
nod *newNod = new nod;
newNod->val = y;
newNod->next = prim[y%666013];
prim[y%666013] = newNod;
// ultim->next = newNod;
// ultim = newNod;
}
}
else
{
prim[y%666013] = new nod;
prim[y%666013]->val = -1;
nod *newN = new nod;
newN->val = y;
newN->next = NULL;
prim[y%666013]->next = newN;
// std::cout<<y<<'\n';
}
}
else
if(x == 2)
{
if(prim[y%666013])
{
// std::cout<<"here2"<<'\n';
nod *val = prim[y%666013];
nod *lastVal = prim[y%666013];
while(val)
{
// std::cout<<val->val<<'\n';
if(val->val == y)
{
lastVal->next = val->next;
delete val;
break;
}
lastVal = val;
val = val->next;
}
val = NULL;
lastVal = val;
// hashu.erase(y);
}
}
else
{
if(prim[y%666013])
{
// std::cout<<"here3"<<'\n';
nod *val = prim[y%666013];
bool found = false;
while(val)
{
if(val->val == y)
{
fout<<1<<'\n';
// std::cout<<1<<'\n';
found = true;
break;
}
val = val->next;
}
val = NULL;
if(!found)
{
fout<<0<<'\n';
// std::cout<<0<<'\n';
}
// fout<<hashu[y]<<'\n';
}
else
{
fout<<0<<'\n';
// std::cout<<0<<'\n';
}
}
}
}
int main()
{
citire();
return 0;
}