cpp
\nclass SnapshotArray {\n    vector<map<int, int>> array;\n    int snapCnt;\npublic:\n    SnapshotArray(int length) {\n        array.resize(length);\n        sn
```\nclass SnapshotArray {\n    vector<map<int, int>> array;\n    int snapCnt;\npublic:\n    SnapshotArray(int length) {\n        array.resize(length);\n        snapCnt=0;\n        for(int i=0; i<length; i++){\n            array[i][snapCnt] = 0;\n        }\n    }\n    \n    void set(int index, int val) {\n        array[index][snapCnt] = val;\n    }\n    \n    int snap() {\n        return snapCnt++;\n    }\n    \n    int get(int index, int snap_id) {\n        auto it = array[index].find(snap_id);\n        if(it != array[index].end()) {\n            return it->second;\n        } else {            \n            auto it = array[index].upper_bound(snap_id);\n            it--;\n            return it->second;\n        }\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```
[]