This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo n,k;
llo mod=1e9+7;
llo it[200001];
llo dp[2001][2001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>k;
for(llo i=0;i<n;i++){
cin>>it[i];
}
dp[0][n-1]=1;
for(llo i=n-2;i>=0;i--){
for(llo j=0;j+i<n;j++){
dp[j][j+i]=0;
llo x=0;
if(j>0){
x=max(x,it[j-1]);
}
if(j+i+1<n){
x=max(x,it[j+i+1]);
}
if(j>0){
if(it[j-1]==x){
dp[j][j+i]+=dp[j-1][j+i];
}
}
if(j+i+1<n){
if(it[j+i+1]==x){
dp[j][j+i]+=dp[j][j+i+1];
}
}
dp[j][j+i]%=mod;
}
}
vector<llo> ss;
for(llo i=0;i<k;i++){
llo aa;
cin>>aa;
ss.pb(aa-1);
}
for(auto j:ss){
cout<<dp[j][j]<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |