Pagini recente » Cod sursa (job #550552) | Cod sursa (job #2688581) | Cod sursa (job #691513) | Cod sursa (job #3167426) | Cod sursa (job #1224055)
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;
class Reader {
public:
Reader(FILE *_stream, const int _size = (1 << 16)):
size(_size),
pointer(0),
buffer(new char[_size]),
stream(_stream) {
assert(fread(buffer, 1, size, stream) != 0);
}
template<class IntType>
IntType NextInt() {
IntType value = 0;
bool negative = false;
while ((Current() < '0' || Current() > '9') && Current() != '-')
NextPosition();
if (Current() == '-') {
negative = true;
NextPosition();
}
while(Current() >= '0' && Current() <= '9') {
value = value * 10 + Current() - '0';
NextPosition();
}
if (negative)
value = -value;
return value;
}
Reader &operator>>(int &value) {
value = NextInt<int>();
return *this;
}
private:
int size, pointer;
char *buffer;
FILE *stream;
char Current() const {
return buffer[pointer];
}
void NextPosition() {
if(++pointer == size) {
assert(fread(buffer, 1, size, stream) != 0);
pointer = 0;
}
}
};
class Hash {
public:
Hash() {}
void Insert(const int value) {
int key = GetKey(value);
if (!Find(value))
table[key].push_back(value);
}
void Erase(const int value) {
int key = GetKey(value);
for (vector<int>::iterator v = table[key].begin(); v != table[key].end(); ++v) {
if (*v == value) {
table[key].erase(v);
return;
}
}
}
bool Find(const int value) {
int key = GetKey(value);
for (vector<int>::iterator v = table[key].begin(); v != table[key].end(); ++v)
if (*v == value)
return true;
return false;
}
private:
static const int U = 666013;
vector<int> table[U];
static int GetKey(const int value) {
return value % U;
}
};
Hash H;
int main() {
assert(freopen("hashuri.in", "r", stdin));
assert(freopen("hashuri.out", "w", stdout));
Reader in = Reader(stdin);
int q; in >> q;
for (; q > 0; --q) {
int type, value;
in >> type >> value;
if (type == 1)
H.Insert(value);
if (type == 2)
H.Erase(value);
if (type == 3)
printf("%d\n", H.Find(value));
}
return 0;
}