This page is still under construction.

Parts of this page are still being built. What you see may change.

Guitar Hero

Time limit1sMemory limit1024 MB

Summary
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 nn notes numbered from 1, and the guitar has mm strings. You are also given qq intervals in the song. An interval is represented by the integers aa and bb, where the first note in the interval has index aa and the last note has index bb.

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 nn, mm, and qq (1≤n,m,q≤1051 \leq n, m, q \leq 10^5). The second line contains nn integers tit_i (1≤ti≤1091 \leq t_i \leq 10^9). Then follow qq lines, each with two integers aia_i and bib_i (1≤ai≤bi≤n1 \leq a_i \leq b_i \leq n).

Output

Print qq lines with "ja" or "nej", one for each interval. Print "ja" if it is possible to place the notes in the interval from aia_i to bib_i so that the requirements are met, otherwise "nej".

Examples1

  1. Example 1

    Input
    7 3 6
    4 1 2 2 3 4 1
    1 7
    2 6
    2 5
    3 3
    1 5
    6 7
    
    Expected output
    nej
    nej
    ja
    ja
    ja
    ja