CCO '22 P1 - Alternating Heights

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 2.0s
Memory limit: 1G

Author:
Problem type
Canadian Computing Olympiad: 2022 Day 1, Problem 1

Troy is planning to take a group photo of the students at CCO and has asked you for help.

There are K students, numbered from 1 to K. Troy has forgotten the students' heights but remembers that no two students have the same height.

Troy has prepared a sequence A1,A2,,AN representing the order of students in the group photo, from left to right. It is possible for a student to appear multiple times in A. You aren't sure how this group photo would be taken, but you're unwilling to assume that Troy made a mistake.

Troy will ask you Q queries of the form x y, which is a compact way of asking "Given the sequence of students, Ax,Ax+1,,Ay, can their heights form an alternating sequence?" More precisely, we denote the height of the ith student as h[i]. If there exists an assignment of heights h[1],h[2],,h[K] such that h[Ax]>h[Ax+1]<h[Ax+2]>h[Ax+3]<h[Ay], answer YES; otherwise, answer NO.

Note that each of the Q queries will be independent: that is, the assignment of heights for query i is independent of the assignment of heights for query j so long as ij.

Input Specification

The first line of input will contain three space-separated integers N, K, and Q.

The second line of input will contain the array A1,A2,,AN (1AiK).

The next Q lines will each contain a query of the form of two space-separated integers x and y (1x<yN).

Marks AwardedBounds on NBounds on KBounds on Q
4 marks2N3000K=21Q106
6 marks2N5002Kmin(N,5)1Q106
7 marks2N30002KN1Q2000
8 marks2N30002KN1Q106

Output Specification

Output Q lines. On the ith line, output the answer to Troy's ith query. Note that the answer is either YES or NO.

Sample Input

Copy
6 3 3
1 1 2 3 1 2
1 2
2 5
2 6

Output for Sample Input

Copy
NO
YES
NO

Explanation of Output for Sample Input

For the first query, we will never have h[1]>h[1], so the answer is no.

For the second query, one solution to h[1]>h[2]<h[3]>h[1] is h[1]=160cm,h[2]=140cm,h[3]=180cm. Another solution could be h[1]=1.55m,h[2]=1.473m,h[3]=1.81m.

For the third query, we cannot have both h[1]>h[2] and h[1]<h[2].


Comments

There are no comments at the moment.