#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[1010101], h[1010101], S[1010101], n, q, i, j;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
h[0] = 1000005;
cin >> n >> q;
for(i = 1, j = 0; i <= n; i++){
cin >> h[i];
for(; j && h[S[j]] < h[i]; j --) dp[h[S[j]]] += (i - S[j]) * (S[j] - S[j - 1]);
S[++j] = i;
}
for(; j; j--) dp[h[S[j]]] += (i - S[j]) * (S[j] - S[j - 1]);
for(i = 1; i <= 1e6; i++) dp[i] += dp[i - 1];
while(q--){
int y; cin >> y;
cout << dp[y] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8232 KB |
Output is correct |
4 |
Correct |
3 ms |
8156 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
3 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8280 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8232 KB |
Output is correct |
4 |
Correct |
3 ms |
8156 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
3 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8280 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8284 KB |
Output is correct |
12 |
Correct |
3 ms |
8060 KB |
Output is correct |
13 |
Correct |
4 ms |
8284 KB |
Output is correct |
14 |
Correct |
4 ms |
8284 KB |
Output is correct |
15 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8232 KB |
Output is correct |
4 |
Correct |
3 ms |
8156 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
3 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8280 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8284 KB |
Output is correct |
12 |
Correct |
3 ms |
8060 KB |
Output is correct |
13 |
Correct |
4 ms |
8284 KB |
Output is correct |
14 |
Correct |
4 ms |
8284 KB |
Output is correct |
15 |
Correct |
4 ms |
8284 KB |
Output is correct |
16 |
Correct |
4 ms |
8284 KB |
Output is correct |
17 |
Correct |
4 ms |
8152 KB |
Output is correct |
18 |
Correct |
4 ms |
8284 KB |
Output is correct |
19 |
Correct |
5 ms |
8284 KB |
Output is correct |
20 |
Correct |
3 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8232 KB |
Output is correct |
4 |
Correct |
3 ms |
8156 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
3 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8280 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8284 KB |
Output is correct |
12 |
Correct |
3 ms |
8060 KB |
Output is correct |
13 |
Correct |
4 ms |
8284 KB |
Output is correct |
14 |
Correct |
4 ms |
8284 KB |
Output is correct |
15 |
Correct |
4 ms |
8284 KB |
Output is correct |
16 |
Correct |
4 ms |
8284 KB |
Output is correct |
17 |
Correct |
4 ms |
8152 KB |
Output is correct |
18 |
Correct |
4 ms |
8284 KB |
Output is correct |
19 |
Correct |
5 ms |
8284 KB |
Output is correct |
20 |
Correct |
3 ms |
8284 KB |
Output is correct |
21 |
Correct |
4 ms |
8280 KB |
Output is correct |
22 |
Correct |
5 ms |
8280 KB |
Output is correct |
23 |
Correct |
4 ms |
8284 KB |
Output is correct |
24 |
Correct |
4 ms |
8284 KB |
Output is correct |
25 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9564 KB |
Output is correct |
2 |
Correct |
14 ms |
9648 KB |
Output is correct |
3 |
Correct |
13 ms |
9564 KB |
Output is correct |
4 |
Correct |
12 ms |
9568 KB |
Output is correct |
5 |
Correct |
11 ms |
9308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
11100 KB |
Output is correct |
2 |
Correct |
26 ms |
10964 KB |
Output is correct |
3 |
Correct |
28 ms |
11092 KB |
Output is correct |
4 |
Correct |
24 ms |
11088 KB |
Output is correct |
5 |
Correct |
21 ms |
10888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
11012 KB |
Output is correct |
2 |
Correct |
24 ms |
11100 KB |
Output is correct |
3 |
Correct |
28 ms |
11088 KB |
Output is correct |
4 |
Correct |
22 ms |
11100 KB |
Output is correct |
5 |
Correct |
31 ms |
11352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8232 KB |
Output is correct |
4 |
Correct |
3 ms |
8156 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
3 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8280 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
10 ms |
9564 KB |
Output is correct |
12 |
Correct |
14 ms |
9648 KB |
Output is correct |
13 |
Correct |
13 ms |
9564 KB |
Output is correct |
14 |
Correct |
12 ms |
9568 KB |
Output is correct |
15 |
Correct |
11 ms |
9308 KB |
Output is correct |
16 |
Correct |
10 ms |
9564 KB |
Output is correct |
17 |
Correct |
18 ms |
9704 KB |
Output is correct |
18 |
Correct |
12 ms |
9564 KB |
Output is correct |
19 |
Correct |
10 ms |
9308 KB |
Output is correct |
20 |
Correct |
12 ms |
9564 KB |
Output is correct |
21 |
Correct |
10 ms |
9308 KB |
Output is correct |
22 |
Correct |
16 ms |
9564 KB |
Output is correct |
23 |
Correct |
15 ms |
9564 KB |
Output is correct |
24 |
Correct |
15 ms |
9468 KB |
Output is correct |
25 |
Correct |
10 ms |
9564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8232 KB |
Output is correct |
4 |
Correct |
3 ms |
8156 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
3 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8280 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8284 KB |
Output is correct |
12 |
Correct |
3 ms |
8060 KB |
Output is correct |
13 |
Correct |
4 ms |
8284 KB |
Output is correct |
14 |
Correct |
4 ms |
8284 KB |
Output is correct |
15 |
Correct |
4 ms |
8284 KB |
Output is correct |
16 |
Correct |
4 ms |
8284 KB |
Output is correct |
17 |
Correct |
4 ms |
8152 KB |
Output is correct |
18 |
Correct |
4 ms |
8284 KB |
Output is correct |
19 |
Correct |
5 ms |
8284 KB |
Output is correct |
20 |
Correct |
3 ms |
8284 KB |
Output is correct |
21 |
Correct |
4 ms |
8280 KB |
Output is correct |
22 |
Correct |
5 ms |
8280 KB |
Output is correct |
23 |
Correct |
4 ms |
8284 KB |
Output is correct |
24 |
Correct |
4 ms |
8284 KB |
Output is correct |
25 |
Correct |
4 ms |
8284 KB |
Output is correct |
26 |
Correct |
10 ms |
9564 KB |
Output is correct |
27 |
Correct |
14 ms |
9648 KB |
Output is correct |
28 |
Correct |
13 ms |
9564 KB |
Output is correct |
29 |
Correct |
12 ms |
9568 KB |
Output is correct |
30 |
Correct |
11 ms |
9308 KB |
Output is correct |
31 |
Correct |
25 ms |
11100 KB |
Output is correct |
32 |
Correct |
26 ms |
10964 KB |
Output is correct |
33 |
Correct |
28 ms |
11092 KB |
Output is correct |
34 |
Correct |
24 ms |
11088 KB |
Output is correct |
35 |
Correct |
21 ms |
10888 KB |
Output is correct |
36 |
Correct |
23 ms |
11012 KB |
Output is correct |
37 |
Correct |
24 ms |
11100 KB |
Output is correct |
38 |
Correct |
28 ms |
11088 KB |
Output is correct |
39 |
Correct |
22 ms |
11100 KB |
Output is correct |
40 |
Correct |
31 ms |
11352 KB |
Output is correct |
41 |
Correct |
10 ms |
9564 KB |
Output is correct |
42 |
Correct |
18 ms |
9704 KB |
Output is correct |
43 |
Correct |
12 ms |
9564 KB |
Output is correct |
44 |
Correct |
10 ms |
9308 KB |
Output is correct |
45 |
Correct |
12 ms |
9564 KB |
Output is correct |
46 |
Correct |
10 ms |
9308 KB |
Output is correct |
47 |
Correct |
16 ms |
9564 KB |
Output is correct |
48 |
Correct |
15 ms |
9564 KB |
Output is correct |
49 |
Correct |
15 ms |
9468 KB |
Output is correct |
50 |
Correct |
10 ms |
9564 KB |
Output is correct |
51 |
Correct |
28 ms |
10836 KB |
Output is correct |
52 |
Correct |
34 ms |
10724 KB |
Output is correct |
53 |
Correct |
27 ms |
10840 KB |
Output is correct |
54 |
Correct |
28 ms |
10844 KB |
Output is correct |
55 |
Correct |
24 ms |
10924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8232 KB |
Output is correct |
4 |
Correct |
3 ms |
8156 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
3 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8280 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8284 KB |
Output is correct |
12 |
Correct |
3 ms |
8060 KB |
Output is correct |
13 |
Correct |
4 ms |
8284 KB |
Output is correct |
14 |
Correct |
4 ms |
8284 KB |
Output is correct |
15 |
Correct |
4 ms |
8284 KB |
Output is correct |
16 |
Correct |
4 ms |
8284 KB |
Output is correct |
17 |
Correct |
4 ms |
8152 KB |
Output is correct |
18 |
Correct |
4 ms |
8284 KB |
Output is correct |
19 |
Correct |
5 ms |
8284 KB |
Output is correct |
20 |
Correct |
3 ms |
8284 KB |
Output is correct |
21 |
Correct |
4 ms |
8280 KB |
Output is correct |
22 |
Correct |
5 ms |
8280 KB |
Output is correct |
23 |
Correct |
4 ms |
8284 KB |
Output is correct |
24 |
Correct |
4 ms |
8284 KB |
Output is correct |
25 |
Correct |
4 ms |
8284 KB |
Output is correct |
26 |
Correct |
10 ms |
9564 KB |
Output is correct |
27 |
Correct |
14 ms |
9648 KB |
Output is correct |
28 |
Correct |
13 ms |
9564 KB |
Output is correct |
29 |
Correct |
12 ms |
9568 KB |
Output is correct |
30 |
Correct |
11 ms |
9308 KB |
Output is correct |
31 |
Correct |
25 ms |
11100 KB |
Output is correct |
32 |
Correct |
26 ms |
10964 KB |
Output is correct |
33 |
Correct |
28 ms |
11092 KB |
Output is correct |
34 |
Correct |
24 ms |
11088 KB |
Output is correct |
35 |
Correct |
21 ms |
10888 KB |
Output is correct |
36 |
Correct |
23 ms |
11012 KB |
Output is correct |
37 |
Correct |
24 ms |
11100 KB |
Output is correct |
38 |
Correct |
28 ms |
11088 KB |
Output is correct |
39 |
Correct |
22 ms |
11100 KB |
Output is correct |
40 |
Correct |
31 ms |
11352 KB |
Output is correct |
41 |
Correct |
10 ms |
9564 KB |
Output is correct |
42 |
Correct |
18 ms |
9704 KB |
Output is correct |
43 |
Correct |
12 ms |
9564 KB |
Output is correct |
44 |
Correct |
10 ms |
9308 KB |
Output is correct |
45 |
Correct |
12 ms |
9564 KB |
Output is correct |
46 |
Correct |
10 ms |
9308 KB |
Output is correct |
47 |
Correct |
16 ms |
9564 KB |
Output is correct |
48 |
Correct |
15 ms |
9564 KB |
Output is correct |
49 |
Correct |
15 ms |
9468 KB |
Output is correct |
50 |
Correct |
10 ms |
9564 KB |
Output is correct |
51 |
Correct |
28 ms |
10836 KB |
Output is correct |
52 |
Correct |
34 ms |
10724 KB |
Output is correct |
53 |
Correct |
27 ms |
10840 KB |
Output is correct |
54 |
Correct |
28 ms |
10844 KB |
Output is correct |
55 |
Correct |
24 ms |
10924 KB |
Output is correct |
56 |
Correct |
206 ms |
36192 KB |
Output is correct |
57 |
Correct |
215 ms |
35928 KB |
Output is correct |
58 |
Correct |
184 ms |
34384 KB |
Output is correct |
59 |
Correct |
178 ms |
34888 KB |
Output is correct |
60 |
Correct |
193 ms |
36684 KB |
Output is correct |