#P10050. [CCO 2022] Alternating Heights
[CCO 2022] Alternating Heights
Problem Description
Troy plans to take a group photo of the CCO students, and he asks you for help.
There are students, numbered from to . Troy forgot the students' heights, but he remembers that no two students have the same height.
Troy has a sequence , representing the order of students in the photo from left to right. A student may appear multiple times in . You are not sure how this photo will be taken, but you do not want to believe that Troy made a mistake.
Troy will give you queries of the form . Each query asks: "Given the student sequence , can their heights form an alternating sequence?" More specifically, let be the height of student . If there exists a height assignment such that $h_{A_{x}}>h_{A_{x+1}}<h_{A_{x+2}}>h_{A_{x+3}}<\ldots h_{A_{y}}$, output YES; otherwise output NO.
Note that each query is independent. That is, the height assignment for query is unrelated to the height assignment for query .
Input Format
The first line contains three integers , , and , separated by spaces.
The second line contains integers representing $A_{1}, A_{2}, \ldots, A_{N}\left(1 \leq A_{i} \leq K\right)$.
The next lines each contain two integers and separated by spaces , describing a query.
Output Format
Output lines. On the -th line, output YES or NO, indicating the answer to Troy's -th query.
6 3 3
1 1 2 3 1 2
1 2
2 5
2 6
NO
YES
NO
Hint
Sample Explanation
For the first query, it is impossible to have , so the answer is NO.
For the second query, one valid assignment for is $h_1=160 \mathrm{~cm}, h_2=140 \mathrm{~cm}, h_3=180 \mathrm{~cm}$. Another valid assignment is $h_1=1.55 \mathrm{~m}, h_2=1.473 \mathrm{~m}, h_3=1.81 \mathrm{~m}$.
For the third query, it is impossible to have both and at the same time.
Constraints
For all testdata, , , .
| Subtask ID | Score | |||
|---|---|---|---|---|
Translated by ChatGPT 5