@@ -28,7 +28,9 @@ class Solution {
28
28
int right = 0 ;
29
29
multiset<int > bst;
30
30
while (right < nums.size ()) {
31
+ cout << " right: " << right << " nextInvalidIndices[right]: " << nextInvalidIndices[right] << endl;
31
32
if (nums[right] < minK || nums[right] > maxK) {
33
+ cout << " reset" << endl;
32
34
bst = multiset<int >();
33
35
right++;
34
36
left = right;
@@ -37,10 +39,22 @@ class Solution {
37
39
38
40
bst.insert (nums[right]);
39
41
42
+ try {
43
+ cout << right << " " ;
44
+ cout << *begin (bst) << " _ " ;
45
+ cout << *prev (end (bst)) << " __ " ;
46
+ cout << *end (bst) << " ___ " << endl;
47
+ } catch (const std::exception& e) {
48
+ cout << " _e_ " << endl;
49
+ }
50
+
40
51
while (bst.size () > 0 && *begin (bst) == minK && *prev (end (bst)) == maxK) {
41
52
int count = nextInvalidIndices[right] - right;
53
+ cout << " add count: " << count << " answer:" << answer << endl;
42
54
answer += count;
43
55
bst.erase (nums[left]);
56
+
57
+ cout << " now: " << *begin (bst) << " _ " << *prev (end (bst)) << endl;
44
58
left++;
45
59
}
46
60
@@ -60,8 +74,11 @@ class Solution {
60
74
int main () {
61
75
Solution soln;
62
76
63
- vector<int > nums{1 ,3 ,5 ,2 ,7 ,5 };
64
- cout << soln.countSubarrays (nums, 1 , 5 ) << endl;
77
+ // vector<int> nums{1,3,5,2,7,5};
78
+
79
+ // cout << soln.countSubarrays(nums, 1, 5) << endl;
80
+ vector<int > nums{35054 ,398719 ,945315 ,945315 ,820417 ,945315 ,35054 ,945315 ,171832 ,945315 ,35054 ,109750 ,790964 ,441974 ,552913 };
81
+ cout << soln.countSubarrays (nums, 35054 , 945315 ) << endl;
65
82
66
83
return 0 ;
67
84
}
0 commit comments