CPP Solution || Map
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n# Code\n\nclass SnapshotArray {\npublic:\n    unordered_map<int, map<int, int>> mp;
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Code\n```\nclass SnapshotArray {\npublic:\n    unordered_map<int, map<int, int>> mp;\n    int s = 0;\n    SnapshotArray(int length) {\n        for(int i = 0; i < length; i++){\n            map<int, int> tmp;\n            tmp[0] = 0;\n            mp[i] = tmp;\n        }\n    }\n\n    void set(int index, int val) {\n        mp[index][s] = val;\n    }\n    \n    int snap() {\n        return s++;\n    }\n    \n    int get(int index, int snap_id) {\n        auto i = mp[index].upper_bound(snap_id); \n        i--;\n        return i -> second;\n    }\n};\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * SnapshotArray* obj = new SnapshotArray(length);\n * obj->set(index,val);\n * int param_2 = obj->snap();\n * int param_3 = obj->get(index,snap_id);\n */\n```
['Binary Search', 'C++']