Pagini recente » Cod sursa (job #2617332) | Cod sursa (job #2231306) | Cod sursa (job #2913779) | Cod sursa (job #1568755) | Cod sursa (job #284430)
Cod sursa(job #284430)
#include <fstream>
#include <algorithm>
using namespace std;
#define NUME "hashuri"
ifstream fi(NUME".in");
ofstream fo(NUME".out");
#define Mod 1000003
#define P 71
struct hitem {
int list[4], size;
inline void push(int x) {
list[size++] = x;
}
inline void remove(int *poz) {
for (poz++; poz < list+size; ++poz)
*(poz-1) = *poz;
size --;
}
inline int *find(int x) {
int *ret = std::find(list, list+size, x);
return (ret != list+size) ? ret : 0;
}
};
hitem H[Mod];
int cauta(hitem &hash, int x, int del = 0)
{
if (int *i = hash.find(x)) {
if (del) hash.remove(i);
return 1;
}
return 0;
}
int main()
{
int N, op, x;
fi >> N;
while (N--) {
fi >> op >> x;
hitem& hash = H[(long long)x*P % Mod];
switch (op) {
case 1:
if (!cauta(hash, x, 0)) {
hash.push(x);
}
break;
case 2:
cauta(hash, x, 1);
break;
case 3:
fo << cauta(hash, x) << "\n";
}
}
return 0;
}