Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 398 Weeks Ago, 2 Days Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 17 Sep 2017 My Price 10.00

space-separated integers

Chef was invited to the party of N people numbered from 1 to N. Chef knows the growth of all the people, i.e. he knows the growth of the ith person is denoted by an integer Ai not exceeding M.

Chef decided to have some fun. At first, he forms K groups of people. The ith group consists of all the people numbered from Li to Ri. Groups may overlap too.

For each group, Chef wants to know the following information: the maximum difference between the numberings of two people having same growth. Formally, Chef wants to know the following:

max{|x - y| : Li = x, y = Ri and Ax = Ay}

Please help Chef to have fun.

Input

There is only one test case in one test file.

The first line of input contains three space-separated integers N, M and K, denoting the number of people, the maximum growth and number of groups respectively. The second line contains N space-separated integers A1, A2, ..., AN denoting the growth of people. Then the ith line of the next K lines contains two space-separated integers Li, Ri, denoting the ith group.

Output

For each group, output the integer denoting the maximum difference between numbering of two people having same growth in a single line.

Constraints and Subtasks

  • 1 = Ai = M
  • 1 = Li = Ri = N

 

Subtask 1: 20 points

  • 1 = N, M, K = 1000 = 103

 

Subtask 2: 80 points

  • 1 = N, M, K = 100000 = 105

Example

Input: 7 7 5 4 5 6 6 5 7 4 6 6 5 6 3 5 3 7 1 7 Output: 0 0 1 1 6

Explanation

Group 1. There is only one person in the group. Thus the maximum difference of numbers should be 0.

Group 2. There are two persons in the group. Their growth are A5 = 5 and A6 = 7. Thus there is no pair of persons who have the same growth. Thus the answer for this group will also be 0.

Group 3. There are three persons in the group. Their growth are A3 = 6, A4 = 6 and A5 = 5. Here person 3 and person 4 has the same growth. Thus the answer is |4 - 3| = 1.

Group 4. There are more persons than the group 3. But they has different growth, other than person 3 and person 4.Thus the answer is also |4 - 3| = 1.

Group 5. This group contains all the people, and person 1 and person 7 has the same growth A1 = A7 = 4. So the answer is |7 - 1| = 6.

Answers

(5)
Status NEW Posted 17 Sep 2017 12:09 PM My Price 10.00

Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll

Not Rated(0)