#P10050. [CCO 2022] Alternating Heights

    ID: 11404 远端评测题 2000ms 1000MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>二分2022CCO(加拿大)深度优先搜索 DFS图论建模双指针 two-pointer

[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 KK students, numbered from 11 to KK. Troy forgot the students' heights, but he remembers that no two students have the same height.

Troy has a sequence A1,A2,,ANA_{1}, A_{2}, \ldots, A_{N}, representing the order of students in the photo from left to right. A student may appear multiple times in AA. 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 QQ queries of the form x,yx, y. Each query asks: "Given the student sequence Ax,Ax+1,,AyA_{x}, A_{x+1}, \ldots, A_{y}, can their heights form an alternating sequence?" More specifically, let hih_i be the height of student ii. If there exists a height assignment h1,h2,,hKh_1, h_2, \ldots, h_K 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 ii is unrelated to the height assignment for query jj (ij)(i \neq j).

Input Format

The first line contains three integers NN, KK, and QQ, separated by spaces.

The second line contains NN integers representing $A_{1}, A_{2}, \ldots, A_{N}\left(1 \leq A_{i} \leq K\right)$.

The next QQ lines each contain two integers xx and yy separated by spaces (1x<yN)(1 \leq x<y \leq N), describing a query.

Output Format

Output QQ lines. On the ii-th line, output YES or NO, indicating the answer to Troy's ii-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 h1>h1h_1>h_1, so the answer is NO.

For the second query, one valid assignment for h1>h2<h3>h1h_1>h_2<h_3>h_1 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 h1>h2h_1>h_2 and h1<h2h_1<h_2 at the same time.

Constraints

For all testdata, 2N30002 \leq N \leq 3000, 2KN2 \leq K \leq N, 1Q1061 \leq Q \leq 10^{6}.

Subtask ID Score NN KK QQ
11 1616 2N30002 \leq N \leq 3000 K=2K=2 1Q1061 \leq Q \leq 10^{6}
22 2424 2N5002 \leq N \leq 500 2Kmin(N,5)2 \leq K \leq \min (N, 5)
33 2828 2N30002 \leq N \leq 3000 2KN2 \leq K \leq N 1Q20001 \leq Q \leq 2000
44 3232 1Q1061 \leq Q \leq 10^{6}

Translated by ChatGPT 5