File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,11 @@ class SnapshotArray {
11
11
if (!A_.count (index)) {
12
12
A_[index].emplace_back (0 , 0 );
13
13
}
14
- A_[index].emplace_back (snap_id_, val);
14
+ if (A_[index].back ().first == snap_id_) {
15
+ A_[index].back ().second = val;
16
+ } else {
17
+ A_[index].emplace_back (snap_id_, val);
18
+ }
15
19
}
16
20
17
21
int snap () {
@@ -23,7 +27,7 @@ class SnapshotArray {
23
27
A_[index].emplace_back (0 , 0 );
24
28
}
25
29
const auto & it = prev (lower_bound (A_[index].cbegin (), A_[index].cend (),
26
- make_pair (snap_id + 1 , 0 )));
30
+ make_pair (snap_id + 1 , numeric_limits< int >:: min () )));
27
31
return it->second ;
28
32
}
29
33
@@ -37,7 +41,7 @@ class SnapshotArray {
37
41
// Space: O(n)
38
42
class SnapshotArray2 {
39
43
public:
40
- SnapshotArray (int length) {
44
+ SnapshotArray2 (int length) {
41
45
}
42
46
43
47
void set (int index, int val) {
You can’t perform that action at this time.
0 commit comments