Snapshot Array
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass SnapshotArray {\npublic:\n    vector<vector<pair<int,int>>> vec;\n    int num = 0;\n    SnapshotArray(int length) {\n        vec.resize(length);\n    }\n    \n    void set(int index, int val) {\n        if(vec[index].empty() || vec[index].back().second != num)\n            vec[index].push_back({val,num});\n        else\n            vec[index].back().first = val;\n    }\n    \n    int snap() {\n        num++;\n        return num - 1;\n    }\n    \n    int get(int index, int snap_id) {\n        int n = vec[index].size();\n        int low = 0,high = n - 1,mid;\n        while(low <= high){\n            mid = low + (high - low)/2;\n            int y = vec[index][mid].second;\n            if(y > snap_id)\n                high = mid - 1;\n            else\n                low = mid + 1;\n\n        }\n        if(high == -1)\n            return 0;\n        return vec[index][high].first;\n    }\n};\n```
['C++']