여러 구간 질의마다 그 구간에서 감소하지 않는 부분수열의 개수(빈 부분수열 포함)를 10^9+7로 나눈 나머지를 구한다.
어려움8동적 계획법분할 정복세그먼트 트리행렬아직 제출이 없습니다시간 제한2초메모리 제한512 MBBessie 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 A_1,A_2,…,A_N of length N (1≤N≤5⋅104) consisting solely of integers in the range 1…K (1≤K≤20). You are given Q (1≤Q≤2⋅105) queries of the form \[L_i,R_i] (1≤L_i≤R_i≤N). For each query, compute the number of non-decreasing subsequences of A_L_i,A_L_i+1…,A_R_i mod 109+7.
A non-decreasing subsequence of A_L,…,A_R is a collection of indices (j_1,j_2,…,j_x) such that L≤j_1\<j_2<⋯\<j_x≤R and A_j_1≤A_j_2≤⋯≤A_j_x. Make sure to consider the empty subsequence!
The first line contains two space-separated integers N and K.
The second line contains N space-separated integers A_1,A_2,…,A_N.
The third line contains a single integer Q.
The next Q lines each contain two space-separated integers L_i and R_i.
For each query \[L_i,R_i], you should print the number of non-decreasing subsequences of A_L_i,A_L_i+1…,A_R_i mod 109+7 on a new line.
For the first query, the non-decreasing subsequences are (),(2), and (3). (2,3) is not a non-decreasing subsequence because A_2≤A_3.
For the second query, the non-decreasing subsequences are (), (4), (5), and (4,5).