시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB1210981.818%

문제

Each morning, when the first rays of sun appear, Ivan has to turn off all the light bulbs in the street lights in his village. His village consists of only one straight road of certain length, and the street lights are located only at one side of the road, denoted with numbers from 1 to N from left to right.

Ivan chooses an initial street light p each day, turns off its light bulb and keeps turning off the light bulbs using a greedy algorithm trying to save electricity. In each step, he looks at the next working light bulb on the left (if there is one) and the next working light bulb on the right (if there is one) and turns off the one with the bigger power. If there isn’t a working light bulb to the left (or the right), he turns off the next light bulb to the right (or the left). If the light bulbs are of equal power, Ivan can choose and turn off any of them. That is why there can be multiple schedules of turning off the light bulbs for an initial position p.

Let us denote the number of different schedules of turning off the light bulbs with M(p) if Ivan’s initial position is p. Write a programme that will, for each of K given initial positions pi determine the modulo of M(pi) when dividing by 109 + 7.

입력

The first line of input contains the integers N and K – the number of street lights and the number of given initial positions.

The second line of input contains N integers A1, A2, . . . AN separated by a single space – the powers of the light bulbs.

The third line of input contains K integers P1, . . . , PK separated by a single space – the initial positions that we’re interested in.

출력

The first and only line of output must contain K integers separated by a single space – the ith integer must be equal to the modulo of M(pi) when dividing by 109 + 7.

제한

In each of the subtasks, it holds 1 ≤ pi ≤ N and 1 ≤ Ai ≤ 200 000.

서브태스크

번호 배점 제한
1 22

1 ≤ N, K ≤ 2 000

2 38

1 ≤ N ≤ 200 000, 1 ≤ K ≤ 5

3 40

1 ≤ N, K ≤ 200 000

예제 입력 1

5 2
3 5 1 4 3
3 5

예제 출력 1

2
1

예제 입력 2

7 7
7 7 7 7 7 7 7
7 6 5 4 3 2 1

예제 출력 2

1
6
15
20
15
6
1

힌트

Clarification of the first example:

If Ivan starts with the third street light, he turns off the light bulb on it – (3, 4, X, 4, 3). The left light bulb has greater power so he turns it off – (3, X, X, 4, 3). Now the right light bulb has greater power so he turns it off – (3, X, X, X, 3). Ivan has two options for the last step because light bulbs #1 and #5 are of equal power.

If Ivan begins from the fifth street lamp, the only way he can turn all the light bulbs off is by moving from right to left and turning them off sequentially

채점 및 기타 정보

  • 예제는 채점하지 않는다.