report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Small range - MarisaOJ: Marisa Online Judge

Small range

Time limit: 1000 ms
Memory limit: 256 MB
Given an integer array $A$ of length $n$. Count the number of subarrays whose maximum and minimum values differ by no more than $k$. ### Input - The first line contains 2 integers $n, k$. - The second line contains $n$ integers $A_i$. ### Output - Print the number of satisfied subarrays. ### Constraints - $1 \le n, k \le 10^5$. - $1 \le k \le 10^9$. - $|A_i| \le 10^9$. ### Example Input: ``` 4 1 1 3 1 2 ``` Output: ``` 5 ```
Introduction to two pointers
Merge array
Brewing potion 2
Unique elements
Small range
Number of pairs
Sum of three values
Brewing potion 3
Brewing potion 4
Three sequences
Biggest submatrix
Choosing numbers
Topic
Two pointers
Rating 800
Solution (2) Solution