Pagini recente » Cod sursa (job #53141) | Cod sursa (job #719331) | Cod sursa (job #1697693) | Cod sursa (job #1947386) | Cod sursa (job #2262428)
#include <bits/stdc++.h>
#define MaxN 1000005
#define MOD 666013
std::ifstream InFile("hashuri.in");
std::ofstream OutFile("hashuri.out");
int N;
template <int P> class HashTable {
public:
inline void Add(int x) {
int Index = x%P,
n = x/P;
ModList[Index].push_back(n);
}
inline void Erase(int x) {
int Index = x%P,
n = x/P;
for (std::list <int>::iterator It = ModList[Index].begin(); It != ModList[Index].end(); ++It)
if (*It == n)
ModList[Index].erase(It),
It = ModList[Index].end();
}
inline bool Find(int x) {
int Index = x%P,
n = x/P;
for (std::list <int>::iterator It = ModList[Index].begin(); It != ModList[Index].end(); ++It)
if (*It == n)
return 1;
return 0;
}
protected:
std::list <int> ModList[P];
}; HashTable <MOD> Hash;
template <int P> inline void Query1(HashTable <P> &Hash) {
int x; InFile >> x;
Hash.Add(x);
}
template <int P> inline void Query2(HashTable <P> &Hash) {
int x; InFile >> x;
Hash.Erase(x);
}
template <int P> inline bool Query3(HashTable <P> &Hash) {
int x; InFile >> x;
return Hash.Find(x);
}
void Citire() {
InFile >> N;
}
void Rezolvare() {
int Type;
while (N--) {
InFile >> Type;
if (Type == 1) {
Query1(Hash);
} else
if (Type == 2) {
Query2(Hash);
}
else
OutFile << Query3(Hash) << '\n';
}
}
int main()
{
Citire();
Rezolvare();
return 0;
}