Submission #330315

# Submission time Handle Problem Language Result Execution time Memory
330315 2020-11-24T18:22:58 Z jungsnow Pilot (NOI19_pilot) C++14
100 / 100
468 ms 40684 KB
#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() {
//    freopen("pilot.inp", "r", stdin);
//    freopen("pilot.out", "w", stdout);
    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';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 7 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 7 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 7 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 7 ms 8172 KB Output is correct
14 Correct 7 ms 8120 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 7 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 7 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 7 ms 8172 KB Output is correct
14 Correct 7 ms 8120 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8188 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 9 ms 8172 KB Output is correct
20 Correct 7 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 7 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 7 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 7 ms 8172 KB Output is correct
14 Correct 7 ms 8120 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8188 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 9 ms 8172 KB Output is correct
20 Correct 7 ms 8172 KB Output is correct
21 Correct 8 ms 8172 KB Output is correct
22 Correct 9 ms 8260 KB Output is correct
23 Correct 7 ms 8172 KB Output is correct
24 Correct 8 ms 8300 KB Output is correct
25 Correct 8 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 9324 KB Output is correct
2 Correct 23 ms 9324 KB Output is correct
3 Correct 19 ms 9324 KB Output is correct
4 Correct 22 ms 9196 KB Output is correct
5 Correct 19 ms 9324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 10604 KB Output is correct
2 Correct 43 ms 10752 KB Output is correct
3 Correct 47 ms 10604 KB Output is correct
4 Correct 43 ms 10732 KB Output is correct
5 Correct 42 ms 10604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 10604 KB Output is correct
2 Correct 48 ms 10604 KB Output is correct
3 Correct 47 ms 10604 KB Output is correct
4 Correct 45 ms 10732 KB Output is correct
5 Correct 48 ms 10732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 7 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 19 ms 9324 KB Output is correct
12 Correct 23 ms 9324 KB Output is correct
13 Correct 19 ms 9324 KB Output is correct
14 Correct 22 ms 9196 KB Output is correct
15 Correct 19 ms 9324 KB Output is correct
16 Correct 19 ms 9324 KB Output is correct
17 Correct 22 ms 9392 KB Output is correct
18 Correct 26 ms 9580 KB Output is correct
19 Correct 19 ms 9324 KB Output is correct
20 Correct 22 ms 9324 KB Output is correct
21 Correct 19 ms 9196 KB Output is correct
22 Correct 21 ms 9324 KB Output is correct
23 Correct 20 ms 9324 KB Output is correct
24 Correct 22 ms 9268 KB Output is correct
25 Correct 20 ms 9324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 7 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 7 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 7 ms 8172 KB Output is correct
14 Correct 7 ms 8120 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8188 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 9 ms 8172 KB Output is correct
20 Correct 7 ms 8172 KB Output is correct
21 Correct 8 ms 8172 KB Output is correct
22 Correct 9 ms 8260 KB Output is correct
23 Correct 7 ms 8172 KB Output is correct
24 Correct 8 ms 8300 KB Output is correct
25 Correct 8 ms 8172 KB Output is correct
26 Correct 19 ms 9324 KB Output is correct
27 Correct 23 ms 9324 KB Output is correct
28 Correct 19 ms 9324 KB Output is correct
29 Correct 22 ms 9196 KB Output is correct
30 Correct 19 ms 9324 KB Output is correct
31 Correct 43 ms 10604 KB Output is correct
32 Correct 43 ms 10752 KB Output is correct
33 Correct 47 ms 10604 KB Output is correct
34 Correct 43 ms 10732 KB Output is correct
35 Correct 42 ms 10604 KB Output is correct
36 Correct 44 ms 10604 KB Output is correct
37 Correct 48 ms 10604 KB Output is correct
38 Correct 47 ms 10604 KB Output is correct
39 Correct 45 ms 10732 KB Output is correct
40 Correct 48 ms 10732 KB Output is correct
41 Correct 19 ms 9324 KB Output is correct
42 Correct 22 ms 9392 KB Output is correct
43 Correct 26 ms 9580 KB Output is correct
44 Correct 19 ms 9324 KB Output is correct
45 Correct 22 ms 9324 KB Output is correct
46 Correct 19 ms 9196 KB Output is correct
47 Correct 21 ms 9324 KB Output is correct
48 Correct 20 ms 9324 KB Output is correct
49 Correct 22 ms 9268 KB Output is correct
50 Correct 20 ms 9324 KB Output is correct
51 Correct 46 ms 10092 KB Output is correct
52 Correct 51 ms 9964 KB Output is correct
53 Correct 46 ms 10220 KB Output is correct
54 Correct 51 ms 9964 KB Output is correct
55 Correct 49 ms 10240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8172 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 7 ms 8172 KB Output is correct
7 Correct 7 ms 8172 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 7 ms 8172 KB Output is correct
10 Correct 8 ms 8172 KB Output is correct
11 Correct 7 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 7 ms 8172 KB Output is correct
14 Correct 7 ms 8120 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8188 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 9 ms 8172 KB Output is correct
20 Correct 7 ms 8172 KB Output is correct
21 Correct 8 ms 8172 KB Output is correct
22 Correct 9 ms 8260 KB Output is correct
23 Correct 7 ms 8172 KB Output is correct
24 Correct 8 ms 8300 KB Output is correct
25 Correct 8 ms 8172 KB Output is correct
26 Correct 19 ms 9324 KB Output is correct
27 Correct 23 ms 9324 KB Output is correct
28 Correct 19 ms 9324 KB Output is correct
29 Correct 22 ms 9196 KB Output is correct
30 Correct 19 ms 9324 KB Output is correct
31 Correct 43 ms 10604 KB Output is correct
32 Correct 43 ms 10752 KB Output is correct
33 Correct 47 ms 10604 KB Output is correct
34 Correct 43 ms 10732 KB Output is correct
35 Correct 42 ms 10604 KB Output is correct
36 Correct 44 ms 10604 KB Output is correct
37 Correct 48 ms 10604 KB Output is correct
38 Correct 47 ms 10604 KB Output is correct
39 Correct 45 ms 10732 KB Output is correct
40 Correct 48 ms 10732 KB Output is correct
41 Correct 19 ms 9324 KB Output is correct
42 Correct 22 ms 9392 KB Output is correct
43 Correct 26 ms 9580 KB Output is correct
44 Correct 19 ms 9324 KB Output is correct
45 Correct 22 ms 9324 KB Output is correct
46 Correct 19 ms 9196 KB Output is correct
47 Correct 21 ms 9324 KB Output is correct
48 Correct 20 ms 9324 KB Output is correct
49 Correct 22 ms 9268 KB Output is correct
50 Correct 20 ms 9324 KB Output is correct
51 Correct 46 ms 10092 KB Output is correct
52 Correct 51 ms 9964 KB Output is correct
53 Correct 46 ms 10220 KB Output is correct
54 Correct 51 ms 9964 KB Output is correct
55 Correct 49 ms 10240 KB Output is correct
56 Correct 454 ms 26812 KB Output is correct
57 Correct 439 ms 40044 KB Output is correct
58 Correct 422 ms 37996 KB Output is correct
59 Correct 434 ms 38636 KB Output is correct
60 Correct 468 ms 40684 KB Output is correct