Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
1.2 kB
0
Indexable
Never
class Solution {
public:
    using ll = long long;
    long long incremovableSubarrayCount(vector<int>& nums) {
        ll ans = 3, n = nums.size();
        int i = 1, l = 0, r = n-1;
        for(int i = 1; i < n-1; i++){
            if(nums[i] > nums[i-1])
                ans++;
            else
                break;
        }
        //cout << ans << ' ';
        for(int i = n-2; i >= 1; i--){
            if(nums[i] < nums[i+1])
                ans++;
            else
                break;
        }
        cout << ans << ' ';
        l = 0, r = n-1;
        int mid = n / 2;
        int l_tmp = 0, r_tmp = 0, okay = 0;
        if(nums[0] < nums[n-1])
            ans++;
        else
            return ans;
        for(int i = l+1; i < mid; i++){
            if(nums[i] > nums[l]){
                l_tmp++;
            }
            else
                break;
        }
        for(int i = r-1; i >= mid; i--){
            if(nums[i] < nums[r]){
                r_tmp++;
            }
            else
                break;
        }
        cout << l_tmp << ' ' << r_tmp;
        return ans + (l_tmp) * (r_tmp);
    }
};
Leave a Comment