#460
Unrated
Non-Decreasing Subsequences
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie was recently taking a USACO contest and encountered the following problem. Of course, Bessie knows how to solve it. But do you?

Consider a sequence A1,A2,,ANA_1,A_2,\ldots,A_N of length NN (1N5104)(1\le N\le 5\cdot 10^4) consisting solely of integers in the range 1K1\ldots K (1K20).(1\le K\le 20). You are given QQ (1Q21051\le Q\le 2\cdot 10^5) queries of the form [Li,Ri][L_i,R_i] (1LiRiN).(1\le L_i\le R_i\le N). For each query, compute the number of non-decreasing subsequences of ALi,ALi+1,ARiA_{L_i},A_{L_i+1}\ldots, A_{R_i} mod 109+710^9+7.

A non-decreasing subsequence of AL,,ARA_L,\ldots,A_R is a collection of indices (j1,j2,,jx)(j_1,j_2,\ldots, j_x) such that Lj1<j2<<jxRL\le j_1<j_2<\cdots<j_x\le R and Aj1Aj2Ajx.A_{j_1}\le A_{j_2}\le \cdots \le A_{j_x}. Make sure to consider the empty subsequence!

SCORING:

Test cases 2-3 satisfy N1000N\le 1000. Test cases 4-6 satisfy K5.K\le 5. Test cases 7-9 satisfy Q105.Q\le 10^5. Test cases 10-12 satisfy no additional constraints.

입력

The first line contains two space-separated integers NN and KK.

The second line contains NN space-separated integers A1,A2,,ANA_1,A_2,\ldots, A_N.

The third line contains a single integer Q.Q.

The next QQ lines each contain two space-separated integers LiL_i and Ri.R_i.

출력

For each query [Li,Ri],[L_i,R_i], you should print the number of non-decreasing subsequences of ALi,ALi+1,ARiA_{L_i},A_{L_i+1}\ldots, A_{R_i} mod 109+710^9+7 on a new line.

예제 입력 1

5 2
1 2 1 1 2
3
2 3
4 5
1 5

예제 출력 1

3
4
20
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.