줄넘기
InterviewTime limit2sMemory limit256 MB
For each query range [l, r], find the longest segment whose two ends have equal heights and no student in between has that same height, or print 0.
- Level
Medium5 of 10
- Topics
- Hash map, Sorting, Implementation
- Solved
- No attempts yet
문제
students stand in a line to jump rope together. The height of student is . You pick some of these students for a group jump rope. The process goes as follows.
First, you pick students with consecutive numbers to be the group. Suppose you pick students from number to number . Students and turn the rope, and the students in between jump over it.
If the two students holding the rope have different heights, the rope is hard to turn, so the two holders must have the same height. (That is, .) Also, if another student in between has the same height, that student gets in the way, so every student in between must have a height different from .
There are queries. In the -th query, only students with numbers from to inclusive may take part in the jump rope. Return the maximum number of students who can take part in the jump rope. If no jump rope is possible, print 0.
입력
The first line contains , the number of students.
The second line contains the heights .
The third line contains , the number of queries.
Each of the next lines contains two integers and .
출력
For each of the queries, print the maximum number of students who can take part in the jump rope, one per line. If no jump rope is possible, print 0.
제한
- ()
- ()