Little Shino and the tournament
Practice
3.8 (42 votes)
Easy
Problem
89% Success 7643 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and \(i^{th}\) fighter will be represented by i. Each fighter has some distinct strength. Rules of the tournament are:

  • Each fight will have 2 fighters.
  • In a fight, fighter with more strength will win.
  • In one round, 1st fighter will fight against 2nd fighter, 3rd fighter will fight against 4th fighter and so on. If there is odd number of fighters, last one will qualify to the next round without fighting.

Input:
First line contains 2 integers, N and Q, number of fighters and number of queries.
Second line contains N space separated integers. \(k^{th}\) integer represents the strength of \(k^{th}\) fighter.
Next Q line contain one integer i each, denoting Q queries.

Output:
For each query, print the number of fights \(i^{th}\) fighter will take part in.

Constraints:
\(1 \le N \le 10^5\)
\(1 \le Q \le 10^6\)
\(1 \le i \le N\)
\(1 \le strength\;of\;fighters \le 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
17 votes
Tags:
EasyImplementationMathProbabilityStatistics
Points:30
4 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementation
Points:30
19 votes
Tags:
Easy