#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int add (int a, int b) {
a += b; if (a >= MOD) a -= MOD;
return a;
}
int n, k, a[200001];
map <pair <int, int>, int> dp;
int ans (int l, int r) {
if (l == 1 || r == n) {
return 1;
}
if (dp.count({l, r})) return dp[{l, r}];
int sum = 0;
int x = max(a[l - 1], a[r + 1]);
if (a[l - 1] == x) sum = add(sum, ans(l - 1, r));
if (a[r + 1] == x) sum = add(sum, ans(l, r + 1));
return dp[{l, r}] = sum;
}
void solve () {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
while (k--) {
int x; cin >> x;
cout << ans(x, x) << '\n';
}
}
signed main () {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
while (t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
100 ms |
25656 KB |
Output is correct |
4 |
Correct |
13 ms |
4440 KB |
Output is correct |
5 |
Correct |
5 ms |
2136 KB |
Output is correct |
6 |
Correct |
7 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1089 ms |
282308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
100 ms |
25656 KB |
Output is correct |
4 |
Correct |
13 ms |
4440 KB |
Output is correct |
5 |
Correct |
5 ms |
2136 KB |
Output is correct |
6 |
Correct |
7 ms |
2652 KB |
Output is correct |
7 |
Execution timed out |
1089 ms |
282308 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |