Pagini recente » Cod sursa (job #3327997) | Cod sursa (job #3322959) | Cod sursa (job #705829) | Cod sursa (job #863884) | Cod sursa (job #3131660)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int N = 1e6 + 10;
vector<vector<int>> buckets(N);
bool existsInBucket(const vector<int>& bucket, int x) {
return find(bucket.begin(), bucket.end(), x) != bucket.end();
}
void insertIntoBucket(vector<int>& bucket, int x) {
if (!existsInBucket(bucket, x)) {
bucket.push_back(x);
}
}
void removeFromBucket(vector<int>& bucket, int x) {
auto it = find(bucket.begin(), bucket.end(), x);
if (it != bucket.end()) {
bucket.erase(it);
}
}
int main() {
int n;
fin >> n;
while (n) {
int op, x;
fin >> op >> x;
int key = x % N;
switch (op) {
case 1: {
insertIntoBucket(buckets[key], x);
break;
}
case 2: {
removeFromBucket(buckets[key], x);
break;
}
case 3: {
bool found = existsInBucket(buckets[key], x);
fout << (found ? "1\n" : "0\n");
break;
}
}
n--;
}
fin.close();
fout.close();
return 0;
}