#P10050. Alternating Heights Arrangement

    ID: 12030 Type: Default 1000ms 256MiB

Alternating Heights Arrangement

Alternating Heights Arrangement

Troy is planning to take a group photo of the students at CCO and needs your help. There are \(K\) students labeled from \(1\) to \(K\), and although Troy forgot their heights, he remembers that no two students have the same height.

Troy provides a sequence \(A_{1}, A_{2}, \ldots, A_{N}\) which indicates the order of the students from left to right in the photo. A student may appear multiple times in \(A\). You are not sure how the photo will be taken, but you wish to assume that Troy made no mistake.

You will be given \(Q\) queries. Each query is in the form \(x,y\) and asks: "For the subsequence \(A_{x}, A_{x+1}, \ldots, A_{y}\), is it possible to assign heights \(h_1, h_2, \ldots, h_K\) (all distinct) such that the heights of the students in the subsequence form an alternating pattern?" More precisely, letting \(h_{i}\) denote the height of student \(i\), you need to determine if there exists an assignment such that \[ h_{A_x} > h_{A_{x+1}} h_{A_{x+3}} < \cdots \;\text{(up to }A_y\text{)} \] If such an assignment exists, output YES; otherwise, output NO.

Note that each query is independent: the height assignment for one query does not affect another.

inputFormat

The first line contains three integers \(K\), \(N\) and \(Q\) separated by spaces: the number of students, the length of the sequence, and the number of queries.

The second line contains \(N\) integers \(A_1, A_2, \ldots, A_N\) representing the student numbers in order.

Each of the next \(Q\) lines contains two integers \(x\) and \(y\) (with \(1 \le x \le y \le N\)), indicating a query on the subsequence \(A_x, A_{x+1}, \ldots, A_y\).

outputFormat

For each query, output a single line containing YES if it is possible to assign the heights to form an alternating sequence as specified, or NO otherwise.

sample

3 5 3
1 2 1 3 2
1 3
2 5
1 5
YES

YES YES

</p>