classRandomizedSet{private:
vector<int> vec;
unordered_map<int,int> mapped;public:/** Initialize your data structure here. */RandomizedSet(){}/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */boolinsert(int val){if(mapped.count(val))returnfalse;
mapped[val]= vec.size();
vec.push_back(val);returntrue;}/** Removes a value from the set. Returns true if the set contained the specified element. */boolremove(int val){if(!mapped.count(val))returnfalse;int idx = mapped[val];
vec[idx]= vec[vec.size()-1];
mapped[vec[idx]]= idx;
mapped.erase(val);
vec.pop_back();returntrue;}/** Get a random element from the set. */intgetRandom(){return vec[rand()%vec.size()];}};