# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
647398 |
2022-10-02T11:41:18 Z |
LeonaRaging |
Pilot (NOI19_pilot) |
C++14 |
|
375 ms |
59936 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define ll long long
#define pb push_back
#define db(val) "[" #val " = " << (val) << "] "
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 4;
const int INF = 1e9;
int n, q, h[maxn], a[maxn], sum[maxn], pre[maxn], nxt[maxn];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen(".INP", "r", stdin);
//freopen(".OUT", "w", stdout);
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= q; i++)
cin >> a[i];
stack<int> st;
h[0] = h[n + 1] = INF;
st.push(0);
for (int i = 1; i <= n; i++) {
while (h[st.top()] < h[i])
st.pop();
pre[i] = st.top();
st.push(i);
}
stack<int>().swap(st);
st.push(n + 1);
for (int i = n; i >= 1; i--) {
while (h[st.top()] <= h[i])
st.pop();
nxt[i] = st.top();
st.push(i);
}
for (int i = 1; i <= n; i++)
sum[h[i]] += (i - pre[i]) * (nxt[i] - i);
for (int i = 1; i <= 1e6; i++)
sum[i] += sum[i - 1];
for (int i = 1; i <= q; i++)
cout << sum[a[i]] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8148 KB |
Output is correct |
2 |
Correct |
7 ms |
8140 KB |
Output is correct |
3 |
Correct |
6 ms |
8148 KB |
Output is correct |
4 |
Correct |
6 ms |
8132 KB |
Output is correct |
5 |
Correct |
6 ms |
8136 KB |
Output is correct |
6 |
Correct |
6 ms |
8148 KB |
Output is correct |
7 |
Correct |
6 ms |
8148 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
6 ms |
8148 KB |
Output is correct |
10 |
Correct |
6 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8148 KB |
Output is correct |
2 |
Correct |
7 ms |
8140 KB |
Output is correct |
3 |
Correct |
6 ms |
8148 KB |
Output is correct |
4 |
Correct |
6 ms |
8132 KB |
Output is correct |
5 |
Correct |
6 ms |
8136 KB |
Output is correct |
6 |
Correct |
6 ms |
8148 KB |
Output is correct |
7 |
Correct |
6 ms |
8148 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
6 ms |
8148 KB |
Output is correct |
10 |
Correct |
6 ms |
8148 KB |
Output is correct |
11 |
Correct |
6 ms |
8148 KB |
Output is correct |
12 |
Correct |
7 ms |
8132 KB |
Output is correct |
13 |
Correct |
7 ms |
8148 KB |
Output is correct |
14 |
Correct |
8 ms |
8148 KB |
Output is correct |
15 |
Correct |
6 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8148 KB |
Output is correct |
2 |
Correct |
7 ms |
8140 KB |
Output is correct |
3 |
Correct |
6 ms |
8148 KB |
Output is correct |
4 |
Correct |
6 ms |
8132 KB |
Output is correct |
5 |
Correct |
6 ms |
8136 KB |
Output is correct |
6 |
Correct |
6 ms |
8148 KB |
Output is correct |
7 |
Correct |
6 ms |
8148 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
6 ms |
8148 KB |
Output is correct |
10 |
Correct |
6 ms |
8148 KB |
Output is correct |
11 |
Correct |
6 ms |
8148 KB |
Output is correct |
12 |
Correct |
7 ms |
8132 KB |
Output is correct |
13 |
Correct |
7 ms |
8148 KB |
Output is correct |
14 |
Correct |
8 ms |
8148 KB |
Output is correct |
15 |
Correct |
6 ms |
8148 KB |
Output is correct |
16 |
Correct |
6 ms |
8148 KB |
Output is correct |
17 |
Correct |
6 ms |
8148 KB |
Output is correct |
18 |
Correct |
6 ms |
8148 KB |
Output is correct |
19 |
Correct |
6 ms |
8148 KB |
Output is correct |
20 |
Correct |
6 ms |
8176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8148 KB |
Output is correct |
2 |
Correct |
7 ms |
8140 KB |
Output is correct |
3 |
Correct |
6 ms |
8148 KB |
Output is correct |
4 |
Correct |
6 ms |
8132 KB |
Output is correct |
5 |
Correct |
6 ms |
8136 KB |
Output is correct |
6 |
Correct |
6 ms |
8148 KB |
Output is correct |
7 |
Correct |
6 ms |
8148 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
6 ms |
8148 KB |
Output is correct |
10 |
Correct |
6 ms |
8148 KB |
Output is correct |
11 |
Correct |
6 ms |
8148 KB |
Output is correct |
12 |
Correct |
7 ms |
8132 KB |
Output is correct |
13 |
Correct |
7 ms |
8148 KB |
Output is correct |
14 |
Correct |
8 ms |
8148 KB |
Output is correct |
15 |
Correct |
6 ms |
8148 KB |
Output is correct |
16 |
Correct |
6 ms |
8148 KB |
Output is correct |
17 |
Correct |
6 ms |
8148 KB |
Output is correct |
18 |
Correct |
6 ms |
8148 KB |
Output is correct |
19 |
Correct |
6 ms |
8148 KB |
Output is correct |
20 |
Correct |
6 ms |
8176 KB |
Output is correct |
21 |
Correct |
7 ms |
8148 KB |
Output is correct |
22 |
Correct |
7 ms |
8148 KB |
Output is correct |
23 |
Correct |
8 ms |
8236 KB |
Output is correct |
24 |
Correct |
7 ms |
8148 KB |
Output is correct |
25 |
Correct |
6 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
10968 KB |
Output is correct |
2 |
Correct |
19 ms |
11132 KB |
Output is correct |
3 |
Correct |
18 ms |
10832 KB |
Output is correct |
4 |
Correct |
17 ms |
10832 KB |
Output is correct |
5 |
Correct |
19 ms |
10876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
13880 KB |
Output is correct |
2 |
Correct |
36 ms |
13932 KB |
Output is correct |
3 |
Correct |
36 ms |
13924 KB |
Output is correct |
4 |
Correct |
35 ms |
13996 KB |
Output is correct |
5 |
Correct |
36 ms |
13884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
14028 KB |
Output is correct |
2 |
Correct |
68 ms |
14096 KB |
Output is correct |
3 |
Correct |
35 ms |
14044 KB |
Output is correct |
4 |
Correct |
37 ms |
14272 KB |
Output is correct |
5 |
Correct |
38 ms |
14216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8148 KB |
Output is correct |
2 |
Correct |
7 ms |
8140 KB |
Output is correct |
3 |
Correct |
6 ms |
8148 KB |
Output is correct |
4 |
Correct |
6 ms |
8132 KB |
Output is correct |
5 |
Correct |
6 ms |
8136 KB |
Output is correct |
6 |
Correct |
6 ms |
8148 KB |
Output is correct |
7 |
Correct |
6 ms |
8148 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
6 ms |
8148 KB |
Output is correct |
10 |
Correct |
6 ms |
8148 KB |
Output is correct |
11 |
Correct |
20 ms |
10968 KB |
Output is correct |
12 |
Correct |
19 ms |
11132 KB |
Output is correct |
13 |
Correct |
18 ms |
10832 KB |
Output is correct |
14 |
Correct |
17 ms |
10832 KB |
Output is correct |
15 |
Correct |
19 ms |
10876 KB |
Output is correct |
16 |
Correct |
17 ms |
10828 KB |
Output is correct |
17 |
Correct |
22 ms |
11100 KB |
Output is correct |
18 |
Correct |
21 ms |
11104 KB |
Output is correct |
19 |
Correct |
22 ms |
10816 KB |
Output is correct |
20 |
Correct |
18 ms |
10984 KB |
Output is correct |
21 |
Correct |
19 ms |
10828 KB |
Output is correct |
22 |
Correct |
21 ms |
10968 KB |
Output is correct |
23 |
Correct |
18 ms |
10992 KB |
Output is correct |
24 |
Correct |
16 ms |
10924 KB |
Output is correct |
25 |
Correct |
20 ms |
10964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8148 KB |
Output is correct |
2 |
Correct |
7 ms |
8140 KB |
Output is correct |
3 |
Correct |
6 ms |
8148 KB |
Output is correct |
4 |
Correct |
6 ms |
8132 KB |
Output is correct |
5 |
Correct |
6 ms |
8136 KB |
Output is correct |
6 |
Correct |
6 ms |
8148 KB |
Output is correct |
7 |
Correct |
6 ms |
8148 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
6 ms |
8148 KB |
Output is correct |
10 |
Correct |
6 ms |
8148 KB |
Output is correct |
11 |
Correct |
6 ms |
8148 KB |
Output is correct |
12 |
Correct |
7 ms |
8132 KB |
Output is correct |
13 |
Correct |
7 ms |
8148 KB |
Output is correct |
14 |
Correct |
8 ms |
8148 KB |
Output is correct |
15 |
Correct |
6 ms |
8148 KB |
Output is correct |
16 |
Correct |
6 ms |
8148 KB |
Output is correct |
17 |
Correct |
6 ms |
8148 KB |
Output is correct |
18 |
Correct |
6 ms |
8148 KB |
Output is correct |
19 |
Correct |
6 ms |
8148 KB |
Output is correct |
20 |
Correct |
6 ms |
8176 KB |
Output is correct |
21 |
Correct |
7 ms |
8148 KB |
Output is correct |
22 |
Correct |
7 ms |
8148 KB |
Output is correct |
23 |
Correct |
8 ms |
8236 KB |
Output is correct |
24 |
Correct |
7 ms |
8148 KB |
Output is correct |
25 |
Correct |
6 ms |
8148 KB |
Output is correct |
26 |
Correct |
20 ms |
10968 KB |
Output is correct |
27 |
Correct |
19 ms |
11132 KB |
Output is correct |
28 |
Correct |
18 ms |
10832 KB |
Output is correct |
29 |
Correct |
17 ms |
10832 KB |
Output is correct |
30 |
Correct |
19 ms |
10876 KB |
Output is correct |
31 |
Correct |
34 ms |
13880 KB |
Output is correct |
32 |
Correct |
36 ms |
13932 KB |
Output is correct |
33 |
Correct |
36 ms |
13924 KB |
Output is correct |
34 |
Correct |
35 ms |
13996 KB |
Output is correct |
35 |
Correct |
36 ms |
13884 KB |
Output is correct |
36 |
Correct |
34 ms |
14028 KB |
Output is correct |
37 |
Correct |
68 ms |
14096 KB |
Output is correct |
38 |
Correct |
35 ms |
14044 KB |
Output is correct |
39 |
Correct |
37 ms |
14272 KB |
Output is correct |
40 |
Correct |
38 ms |
14216 KB |
Output is correct |
41 |
Correct |
17 ms |
10828 KB |
Output is correct |
42 |
Correct |
22 ms |
11100 KB |
Output is correct |
43 |
Correct |
21 ms |
11104 KB |
Output is correct |
44 |
Correct |
22 ms |
10816 KB |
Output is correct |
45 |
Correct |
18 ms |
10984 KB |
Output is correct |
46 |
Correct |
19 ms |
10828 KB |
Output is correct |
47 |
Correct |
21 ms |
10968 KB |
Output is correct |
48 |
Correct |
18 ms |
10992 KB |
Output is correct |
49 |
Correct |
16 ms |
10924 KB |
Output is correct |
50 |
Correct |
20 ms |
10964 KB |
Output is correct |
51 |
Correct |
41 ms |
13140 KB |
Output is correct |
52 |
Correct |
40 ms |
13024 KB |
Output is correct |
53 |
Correct |
37 ms |
13168 KB |
Output is correct |
54 |
Correct |
36 ms |
13004 KB |
Output is correct |
55 |
Correct |
35 ms |
13140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8148 KB |
Output is correct |
2 |
Correct |
7 ms |
8140 KB |
Output is correct |
3 |
Correct |
6 ms |
8148 KB |
Output is correct |
4 |
Correct |
6 ms |
8132 KB |
Output is correct |
5 |
Correct |
6 ms |
8136 KB |
Output is correct |
6 |
Correct |
6 ms |
8148 KB |
Output is correct |
7 |
Correct |
6 ms |
8148 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
6 ms |
8148 KB |
Output is correct |
10 |
Correct |
6 ms |
8148 KB |
Output is correct |
11 |
Correct |
6 ms |
8148 KB |
Output is correct |
12 |
Correct |
7 ms |
8132 KB |
Output is correct |
13 |
Correct |
7 ms |
8148 KB |
Output is correct |
14 |
Correct |
8 ms |
8148 KB |
Output is correct |
15 |
Correct |
6 ms |
8148 KB |
Output is correct |
16 |
Correct |
6 ms |
8148 KB |
Output is correct |
17 |
Correct |
6 ms |
8148 KB |
Output is correct |
18 |
Correct |
6 ms |
8148 KB |
Output is correct |
19 |
Correct |
6 ms |
8148 KB |
Output is correct |
20 |
Correct |
6 ms |
8176 KB |
Output is correct |
21 |
Correct |
7 ms |
8148 KB |
Output is correct |
22 |
Correct |
7 ms |
8148 KB |
Output is correct |
23 |
Correct |
8 ms |
8236 KB |
Output is correct |
24 |
Correct |
7 ms |
8148 KB |
Output is correct |
25 |
Correct |
6 ms |
8148 KB |
Output is correct |
26 |
Correct |
20 ms |
10968 KB |
Output is correct |
27 |
Correct |
19 ms |
11132 KB |
Output is correct |
28 |
Correct |
18 ms |
10832 KB |
Output is correct |
29 |
Correct |
17 ms |
10832 KB |
Output is correct |
30 |
Correct |
19 ms |
10876 KB |
Output is correct |
31 |
Correct |
34 ms |
13880 KB |
Output is correct |
32 |
Correct |
36 ms |
13932 KB |
Output is correct |
33 |
Correct |
36 ms |
13924 KB |
Output is correct |
34 |
Correct |
35 ms |
13996 KB |
Output is correct |
35 |
Correct |
36 ms |
13884 KB |
Output is correct |
36 |
Correct |
34 ms |
14028 KB |
Output is correct |
37 |
Correct |
68 ms |
14096 KB |
Output is correct |
38 |
Correct |
35 ms |
14044 KB |
Output is correct |
39 |
Correct |
37 ms |
14272 KB |
Output is correct |
40 |
Correct |
38 ms |
14216 KB |
Output is correct |
41 |
Correct |
17 ms |
10828 KB |
Output is correct |
42 |
Correct |
22 ms |
11100 KB |
Output is correct |
43 |
Correct |
21 ms |
11104 KB |
Output is correct |
44 |
Correct |
22 ms |
10816 KB |
Output is correct |
45 |
Correct |
18 ms |
10984 KB |
Output is correct |
46 |
Correct |
19 ms |
10828 KB |
Output is correct |
47 |
Correct |
21 ms |
10968 KB |
Output is correct |
48 |
Correct |
18 ms |
10992 KB |
Output is correct |
49 |
Correct |
16 ms |
10924 KB |
Output is correct |
50 |
Correct |
20 ms |
10964 KB |
Output is correct |
51 |
Correct |
41 ms |
13140 KB |
Output is correct |
52 |
Correct |
40 ms |
13024 KB |
Output is correct |
53 |
Correct |
37 ms |
13168 KB |
Output is correct |
54 |
Correct |
36 ms |
13004 KB |
Output is correct |
55 |
Correct |
35 ms |
13140 KB |
Output is correct |
56 |
Correct |
352 ms |
58492 KB |
Output is correct |
57 |
Correct |
331 ms |
58536 KB |
Output is correct |
58 |
Correct |
316 ms |
55760 KB |
Output is correct |
59 |
Correct |
340 ms |
56756 KB |
Output is correct |
60 |
Correct |
375 ms |
59936 KB |
Output is correct |