C++ easy implementation using STL methods
```\nclass SnapshotArray {\npublic:\n    vector>> data;\n    int snapIdx;\n    SnapshotArray(int length) {\n        data.resize(length);\n        snapIdx = 0;\n
```\nclass SnapshotArray {\npublic:\n    vector<vector<pair<int, int>>> data;\n    int snapIdx;\n    SnapshotArray(int length) {\n        data.resize(length);\n        snapIdx = 0;\n    }\n    \n    void set(int index, int val) {\n        if (data[index].empty() || data[index].back().first < snapIdx)\n            data[index].emplace_back(snapIdx, val);\n        else\n            data[index].back().second = val;\n    }\n    \n    int snap() {\n        return snapIdx++;\n    }\n    \n    int get(int index, int snap_id) {\n        auto it = upper_bound(data[index].begin(), data[index].end(), make_pair(snap_id, INT_MAX));\n        if (it == data[index].begin())  // no data at snap_id\n            return 0;\n        else    // return the data with snapIdx <= snap_id, which is the prev of upper_bound\n            return prev(it)->second;\n    }\n};
[]