#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1000100;
int N, Q, H[maxn];
int L[maxn], R[maxn];
ll Ans[maxn];
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr);
cin >> N >> Q;
stack<int> st;
for (int i = 1; i <= N; ++i) {
cin >> H[i];
while (!st.empty() && H[st.top()] <= H[i]) st.pop();
if (st.empty()) L[i] = 1;
else L[i] = st.top() + 1;
st.push(i);
}
while (!st.empty()) st.pop();
for (int i = N; i >= 1; --i) {
while (!st.empty() && H[st.top()] <= H[i]) st.pop();
if (st.empty()) R[i] = N;
else R[i] = st.top() - 1;
st.push(i);
Ans[H[i]] += 1ll * (R[i] - i + 1) * (i - L[i] + 1);
}
for (int i = 1; i <= 1000000; ++i) Ans[i] += Ans[i - 1];
for (int i = 1; i <= Q; ++i) {
int Y; cin >> Y;
cout << Ans[Y] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
7 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8300 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
7 ms |
8172 KB |
Output is correct |
6 |
Incorrect |
7 ms |
8172 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
7 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8300 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
7 ms |
8172 KB |
Output is correct |
6 |
Incorrect |
7 ms |
8172 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
7 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8300 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
7 ms |
8172 KB |
Output is correct |
6 |
Incorrect |
7 ms |
8172 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
7 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8300 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
7 ms |
8172 KB |
Output is correct |
6 |
Incorrect |
7 ms |
8172 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
9344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
10604 KB |
Output is correct |
2 |
Correct |
51 ms |
10732 KB |
Output is correct |
3 |
Correct |
49 ms |
10604 KB |
Output is correct |
4 |
Correct |
43 ms |
10732 KB |
Output is correct |
5 |
Correct |
44 ms |
10604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
10664 KB |
Output is correct |
2 |
Correct |
46 ms |
10604 KB |
Output is correct |
3 |
Correct |
46 ms |
10604 KB |
Output is correct |
4 |
Correct |
45 ms |
10732 KB |
Output is correct |
5 |
Correct |
48 ms |
10732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
7 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8300 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
7 ms |
8172 KB |
Output is correct |
6 |
Incorrect |
7 ms |
8172 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
7 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8300 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
7 ms |
8172 KB |
Output is correct |
6 |
Incorrect |
7 ms |
8172 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
7 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8300 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
7 ms |
8172 KB |
Output is correct |
6 |
Incorrect |
7 ms |
8172 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |