Pagini recente » Cod sursa (job #1294189) | Cod sursa (job #882258) | Monitorul de evaluare | Cod sursa (job #2786019) | Cod sursa (job #959897)
Cod sursa(job #959897)
#include <fstream>
#include <vector>
using namespace std;
#define key 666013
#define in "hashuri.in"
#define out "hashuri.out"
#define h(x) ((x)%key)
typedef vector <int> :: iterator IT;
vector <int> list[key];
int n, t, x;
IT search(int x) {
for (IT it = list[h(x)].begin(); it != list[h(x)].end(); ++it)
if (*it == x)
return it;
return list[h(x)].end();
}
void add(int x) {
if (search(x) == list[h(x)].end())
list[h(x)].push_back (x);
}
void erase(int x) {
IT it = search(x);
if (it != list[h(x)].end())
list[h(x)].erase(it);
}
int main() {
ifstream fin (in);
fin >> n;
ofstream fout (out);
for (int i = 0; i < n; ++i) {
fin >> t >> x;
if (t == 1)
add(x);
if (t == 2)
erase(x);
if (t == 3) {
IT it = search(x);
fout << ((it == list[h(x)].end()) ? 0 : 1) << "\n";
}
}
fcloseall();
return 0;
}