Tap here to switch tabs
Problem
Submissions

Problem: Count Stable Subarrays

Count Stable Subarrays asks you to count, for each index range query, the contiguous subarrays within it whose values are in nondecreasing order.

Statement

You are given an integer array nums and a 2D2 {D} integer array queries, where each queries[i] is a pair of indices [li,ri][l_i, r_i].

A subarray is considered stable if its elements appear in non decreasing order.

For each query queries[i], determine the number of stable subarrays contained entirely within the range [li,ri][l_i, r_i] of nums.

Return an array ans where ans[i] represents the answer to the ithi^{ {th}} query.

Note: A subarray of length 11 is always considered stable.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i] = [l_i, r_i]

  • 0≤li≤ri≤0 \leq l_i \leq r_i \leq nums.length −1- 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Stable Subarrays

Count Stable Subarrays asks you to count, for each index range query, the contiguous subarrays within it whose values are in nondecreasing order.

Statement

You are given an integer array nums and a 2D2 {D} integer array queries, where each queries[i] is a pair of indices [li,ri][l_i, r_i].

A subarray is considered stable if its elements appear in non decreasing order.

For each query queries[i], determine the number of stable subarrays contained entirely within the range [li,ri][l_i, r_i] of nums.

Return an array ans where ans[i] represents the answer to the ithi^{ {th}} query.

Note: A subarray of length 11 is always considered stable.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i] = [l_i, r_i]

  • 0≤li≤ri≤0 \leq l_i \leq r_i \leq nums.length −1- 1