Pagini recente » Cod sursa (job #2752175) | Cod sursa (job #1936194) | Cod sursa (job #2778427) | Cod sursa (job #1953991) | Cod sursa (job #1971401)
#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 = 1000457;
vector <int> h[MOD];
void insert(int nr) {
int b = nr % MOD;
for (auto it: h[b])
if (it == nr)
return ;
h[b].push_back(nr);
}
void erase(int nr) {
int b = nr % MOD;
for (int i = 0; i < h[b].size(); ++ i)
if (h[b][i] == nr) {
swap(h[b][i], h[b].back());
h[b].pop_back();
break;
}
}
bool find(int nr) {
int b = nr % MOD;
for (auto it: h[b])
if (it == nr)
return true;
return false;
}
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;
}