classRandomizedCollection{public:
vector<int> num;
unordered_map<int, unordered_set<int>> ms;/** Initialize your data structure here. */RandomizedCollection(){}/** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */boolinsert(int val){
num.push_back(val);
ms[val].insert(num.size()-1);return ms[val].size()==1;}/** Removes a value from the collection. Returns true if the collection contained the specified element. */boolremove(int val){if(ms.find(val)== ms.end())returnfalse;int index =*ms[val].begin();
num[index]= num[num.size()-1];
ms[val].erase(index);
ms[num[index]].erase(num.size()-1);if(index < num.size()-1) ms[num[index]].insert(index);if(ms[val].size()==0) ms.erase(val);
num.pop_back();returntrue;}/** Get a random element from the collection. */intgetRandom(){return num[rand()% num.size()];}};