Guitar Hero
Time limit1sMemory limit1024 MB
Given a sequence of note pitches and m strings, decide for each query interval whether its notes can be assigned to strings following the pitch-to-string monotonicity rules.
- Level
Medium6 of 10
- Topics
- Prefix sum, Greedy, Array, Implementation
- Solved
- No attempts yet
Problem
In the 100% original game String Instrument Champion, the notes of a song are shown as points on the strings of a guitar. Notes are represented as integers, and the integer is the pitch of the note. No two notes are played at the same time in any String Instrument Champion song.
A song can contain far more notes than there are strings on the guitar. So we place the notes on the strings according to a set of rules. Sometimes this works out, but not always. When we place the notes on the strings, we have the following requirements:
- The first note may be on any string.
- If the previous note had a lower pitch than the next note, the next note must be on a higher string.
- If the previous note had a higher pitch than the next note, the next note must be on a lower string.
- If the previous note had the same pitch as the next note, the next note must be on the same string.
You are given a song with notes numbered from 1, and the guitar has strings. You are also given intervals in the song. An interval is represented by the integers and , where the first note in the interval has index and the last note has index .
For each interval we now ask: is it possible to place the notes contained in the interval on strings so that the requirements are met?
Input
The first line contains three integers , , and (). The second line contains integers (). Then follow lines, each with two integers and ().
Output
Print lines with "ja" or "nej", one for each interval. Print "ja" if it is possible to place the notes in the interval from to so that the requirements are met, otherwise "nej".