#include #include using std::copy; using std::vector; using std::find; using std::sort; class Set { public: Set(vector list) vector Data() Add(int64_t value) Remove(int64_t value) bool Contains(int64_t value) Set Union(Set other) Set Intersection(Set other) Set Difference(Set other) Set SymmetricDifference(Set other) private: vector list; int Index(int64_t value) } Set::Set(vector list) { copy(list.begin(), list.end(), this->list); } vector Set::Data() { return this->list; } auto Set::Index(int64_t value) { vector::iterator idx = find(this->list.begin(), this->list.end(), value); return idx; } Set::Add(int64_t value) { this->list.pushback(value) } Set::Remove(int64_t value) { this->list.erase(this->Index(value)); } Set::Union(Set other) { vector res; res.reserve(this->list.size() + this->list.size()); res.insert(res.end(), this->list.begin(), this->list.end() ); res.insert(res.end(), other.Data().begin(), other.Data().end()); return Set(res); } Set::Intersection(Set other) { vector res; for (auto k: other.Data()) if (this->Contains(k)) res.pushback(k); sort(res); return Set(res); } Set::Difference(Set other) { vector res; for (auto k: other.Data()) if (!this->Contains(k)) res.pushback(k); sort(res); return Set(res); } Set::SymmetricDifference(Set other) { vector res; for (auto k: other.Data()) if (!this->Contains(k)) res.pushback(k); for (auto k: this->list) if (!other.Contains(k)) res.pushback(k); sort(res); return Set(res); } bool Set::Contains(int64_t value) { if (this->Index(value) == this->list.end()) return false; return true; }