Pagini recente » Cod sursa (job #2347134) | Cod sursa (job #853289) | Cod sursa (job #2856813) | Cod sursa (job #1768811) | Cod sursa (job #1971412)
#include <fstream>
#include <iostream>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
class InputReader {
public:
InputReader(const char *fileName) {
in = fopen(fileName, "r");
fread(buffer, 1, SIZE, in);
cursor = 0;
}
template <typename T>
InputReader& operator>>(T &nr) {
while (!isdigit(buffer[cursor]))
advance();
nr = 0;
while (isdigit(buffer[cursor])) {
nr *= 10;
nr += buffer[cursor] - '0';
advance();
}
return (*this);
}
private:
FILE *in;
static const int SIZE = (1 << 17);
int cursor;
char buffer[SIZE];
void advance() {
++ cursor;
if (cursor == SIZE) {
int cnt = fread(buffer, 1, SIZE, in);
if (cnt < SIZE)
buffer[cnt] = 0;
cursor = 0;
}
}
};
class OutputWriter {
public:
OutputWriter(const char *fileName) {
out = fopen(fileName, "w");
cursor = 0;
}
~OutputWriter() {
flush();
}
OutputWriter& operator<<(const int &ch) {
char digits[4];
int cnt = 0;
int _ch = ch;
do {
digits[cnt ++] = _ch % 10 + '0';
_ch /= 10;
} while (_ch);
for (int i = cnt - 1; i >= 0; -- i)
(*this) << digits[i];
return (*this);
}
OutputWriter& operator<<(const char &ch) {
if (cursor == SIZE)
flush();
buffer[cursor ++] = ch;
return (*this);
}
void flush() {
fwrite(buffer, 1, cursor, out);
cursor = 0;
}
private:
static const int SIZE = (1 << 17);
FILE *out;
char buffer[SIZE];
int cursor;
};
bool prime(int nr) {
if (nr <= 1)
return false;
for (int i = 2; i * i <= nr; ++ i)
if (nr % i == 0)
return false;
return true;
}
const int MOD = 1048576;
int C1 = 71;
int C2 = 79;
int C3 = 1003;
bool V[MOD];
void insert(int nr) {
V[(nr * C1) & (MOD - 1)] = 1;
V[(nr * C2) & (MOD - 1)] = 1;
V[(nr * C3) & (MOD - 1)] = 1;
}
void erase(int nr) {
V[(nr * C1) & (MOD - 1)] = 0;
}
bool find(int nr) {
return V[(nr * C1) & (MOD - 1)] &&
V[(nr * C2) & (MOD - 1)] &&
V[(nr * C3) & (MOD - 1)];
}
int main()
{
/*MOD = 1000500;
while (!prime(MOD))
-- MOD;
cout << MOD << endl;*/
InputReader cin("hashuri.in");
OutputWriter cout("hashuri.out");
int M = 0;
cin >> M;
for (int i = 1; i <= M; ++ i) {
int type, x;
cin >> type >> x;
if (type == 1)
insert(x);
else if (type == 2)
erase(x);
else
cout << find(x) << '\n';
}
return 0;
}