Sequence and Queries 36
Time limit1sMemory limit512 MB
Given distinct values 1 to N, for each query [l, r] count the pairs x at most y inside it where max minus min equals y minus x.
- Level
Hard8 of 10
- Topics
- Array, Sliding window, Divide and conquer
- Solved
- No attempts yet
Problem
A sequence of length is given. Every number in the sequence is between 1 and inclusive, and all numbers are distinct. Write a program that handles the following query.
l r: Print the number of integer pairs with that satisfy .
Input
The first line contains the size of the sequence . ()
The second line contains . All numbers are distinct. ()
The third line contains the number of queries . ()
Each of the following lines contains one query. ()
Output
Print the result of each query on its own line.