Coding Championship

0

0 votes
Medium
Problem

In the coding championship, We got N top coders around the world.

This was a single participant coding competition and contained a lot of rounds depending on the number of coders participated.

As there were N coders, each coder had some distinct coding skills. The coding skills of ith coder will be represented by i.

This competition was a bit different from other coding contests. Here In each round, two coders submitted their solution on one question. The coder which had more coding skills took less time to submit that and got ACCEPTED.

Now, In one round, 1st and 2nd coder submitted their solutions on one problem and this is considered to be one match. 3rd and 4th coder submitted their solutions on another problem and so on. This is how matches happened between coders and each match had a different problem. If there was an odd number of coders then the last one got qualified for the next round directly without even a match.

You are given Q queries where each query contains number i, and you have to find the number of matches that ith coder took part in.

INPUT

  • The first line of the input contains two integers N(Number of coders) and Q(Number of queries).

  • The second line contains N space separated integers(Coding skills of coders)  i1, i2, i3, i4, . . . . , iN

OUTPUT

For each query print a single line containing a number of matches played by the ith coder.

CONSTRAINTS

1<=N<=105

1<=Q<=106

1<=i<=N

1<=Coding skills of coders<=109

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

The matches in the first round will be between (1, 2) and (3, 4).

From the match between (1, 2), 2 will win and from the match between (3, 4), 4 will win.

Second round will have 3 coders left. {2, 4, 5}.

In second round there will be one match between (2, 4) and 4 will win.

Third round will have 2 coders left. {4, 5}

There will be one match in the third round between (4, 5) and 5 will win.

Number of matches 1 took part in: 1

Number of matches 2 took part in: 2

Number of matches 3 took part in: 1

Number of matches 4 took part in: 3

Number of matches 5 took part in: 1

Editor Image

?