-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnapshot-array.cpp
More file actions
33 lines (28 loc) · 787 Bytes
/
Copy pathsnapshot-array.cpp
File metadata and controls
33 lines (28 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class SnapshotArray {
public:
// ????contest-148????????????AC?
SnapshotArray(int length) {}
void set(int index, int val) {
um[index][snap_id]=val;
}
int snap() {
return snap_id++;
}
int get(int index, int snap_id) {
if(um.find(index)==um.end()) return 0;
auto &u=um[index]; // ?????????????????
auto it=u.upper_bound(snap_id);
if(it==u.begin()) return 0;
it--;
return it->second;
}
int snap_id=0;
unordered_map<int, map<int,int>> um;
};
/**
* Your SnapshotArray object will be instantiated and called as such:
* SnapshotArray* obj = new SnapshotArray(length);
* obj->set(index,val);
* int param_2 = obj->snap();
* int param_3 = obj->get(index,snap_id);
*/