#include #include #include /* The number container system can do the following: 1. insert or replace a number at the given index 2. return the smallest index for the given number in the system */ class NumberContainers { private: std::unordered_map nums; std::unordered_map, std::greater>> heap; public: NumberContainers() = default; void change(int index, int number) { nums[index] = number; heap[number].push(index); } int find(int number) { while (!heap[number].empty() && nums[heap[number].top()] != number) { heap[number].pop(); } if (heap[number].empty()) { return -1; } return heap[number].top(); } };