Logo
(追記) (追記ここまで)

11959번 - PROKLETNIK 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 128 MB91161424.138%

문제

Young Luka is about to enter a house with the evil witch Marica inside. As soon as he enters the house, she asks him questions about her array of N numbers. Luka fearfully asks for a clarification of the questions. Marica explains to him that each query consists of two integers L and R which represent the positions of a contiguous sub-array in her array.

It is Luka’s task to answer for each query what the longest contiguous sub-array of that contiguous sub-array (it can be the entire sub-array) having the property of being magical. An array is called magical if all the values are between the values of the first and last number in that array. For example, [1 3 1 2 4] is magical, the same as [4 1 1 2 1], whereas [3 3 4 1] is not magical.

입력

The first line of input contains the integer N (1 ≤ N ≤ 500 000), the number of numbers in the array.

The second line contains N integers ai (1 ≤ ai ≤ 109). The third line contains the integer Q (1 ≤ Q ≤ 500 000), the number of queries. Each of the following Q lines contains two integers, L and R (1 ≤ L ≤ R ≤ N), representing the sub-array from the query.

출력

The ith line of output must contain a single integer – the answer to the ith query.

제한

예제 입력 1

5
5 4 3 3 2
3
1 2
1 1
2 4

예제 출력 1

2
1
3

예제 입력 2

6
6 6 5 1 6 2
3
4 5
4 6
1 4

예제 출력 2

2
2
4

힌트

출처

Contest > Croatian Open Competition in Informatics > COCI 2015/2016 > Contest #7 6번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /