Submission #336419

# Submission time Handle Problem Language Result Execution time Memory
336419 2020-12-15T09:36:53 Z ncduy0303 Pilot (NOI19_pilot) C++17
100 / 100
448 ms 40556 KB
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e6 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

ll ps[MAX_N];

void solve() {
    int n, q; cin >> n >> q;
    vector<int> a(n), l(n), r(n);
    for (int &x : a) cin >> x;
    stack<int> st;
    for (int i = 0; i < n; i++) {
        while (st.size() && a[st.top()] <= a[i]) st.pop();
        l[i] = st.size() ? st.top() + 1 : 0;
        st.push(i);
    }
    while (st.size()) st.pop();
    for (int i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] < a[i]) st.pop();
        r[i] = st.size() ? st.top() - 1 : n - 1;
        st.push(i);
    }
    for (int i = 0; i < n; i++) ps[a[i]] += (ll)(i - l[i] + 1) * (r[i] - i + 1);
    for (int i = 1; i < MAX_N; i++) ps[i] += ps[i - 1];
    while (q--) {
        int x; cin >> x;
        cout << ps[x] << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}
# 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 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 7 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 8172 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 7 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 8172 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 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 7 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 8172 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 7 ms 8172 KB Output is correct
21 Correct 7 ms 8192 KB Output is correct
22 Correct 7 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 7 ms 8172 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 9324 KB Output is correct
2 Correct 21 ms 9324 KB Output is correct
3 Correct 19 ms 9196 KB Output is correct
4 Correct 20 ms 9196 KB Output is correct
5 Correct 19 ms 9196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 10604 KB Output is correct
2 Correct 44 ms 10732 KB Output is correct
3 Correct 51 ms 10604 KB Output is correct
4 Correct 45 ms 10732 KB Output is correct
5 Correct 43 ms 10604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 10732 KB Output is correct
2 Correct 46 ms 10604 KB Output is correct
3 Correct 47 ms 10604 KB Output is correct
4 Correct 46 ms 10732 KB Output is correct
5 Correct 47 ms 10860 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 7 ms 8172 KB Output is correct
11 Correct 19 ms 9324 KB Output is correct
12 Correct 21 ms 9324 KB Output is correct
13 Correct 19 ms 9196 KB Output is correct
14 Correct 20 ms 9196 KB Output is correct
15 Correct 19 ms 9196 KB Output is correct
16 Correct 18 ms 9196 KB Output is correct
17 Correct 21 ms 9324 KB Output is correct
18 Correct 22 ms 9324 KB Output is correct
19 Correct 19 ms 9196 KB Output is correct
20 Correct 21 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 20 ms 9196 KB Output is correct
25 Correct 19 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 7 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 8172 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 7 ms 8172 KB Output is correct
21 Correct 7 ms 8192 KB Output is correct
22 Correct 7 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 7 ms 8172 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
26 Correct 19 ms 9324 KB Output is correct
27 Correct 21 ms 9324 KB Output is correct
28 Correct 19 ms 9196 KB Output is correct
29 Correct 20 ms 9196 KB Output is correct
30 Correct 19 ms 9196 KB Output is correct
31 Correct 42 ms 10604 KB Output is correct
32 Correct 44 ms 10732 KB Output is correct
33 Correct 51 ms 10604 KB Output is correct
34 Correct 45 ms 10732 KB Output is correct
35 Correct 43 ms 10604 KB Output is correct
36 Correct 46 ms 10732 KB Output is correct
37 Correct 46 ms 10604 KB Output is correct
38 Correct 47 ms 10604 KB Output is correct
39 Correct 46 ms 10732 KB Output is correct
40 Correct 47 ms 10860 KB Output is correct
41 Correct 18 ms 9196 KB Output is correct
42 Correct 21 ms 9324 KB Output is correct
43 Correct 22 ms 9324 KB Output is correct
44 Correct 19 ms 9196 KB Output is correct
45 Correct 21 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 20 ms 9196 KB Output is correct
50 Correct 19 ms 9324 KB Output is correct
51 Correct 46 ms 10092 KB Output is correct
52 Correct 50 ms 9964 KB Output is correct
53 Correct 47 ms 10220 KB Output is correct
54 Correct 48 ms 9964 KB Output is correct
55 Correct 45 ms 10092 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 7 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 8172 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 7 ms 8172 KB Output is correct
21 Correct 7 ms 8192 KB Output is correct
22 Correct 7 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 7 ms 8172 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
26 Correct 19 ms 9324 KB Output is correct
27 Correct 21 ms 9324 KB Output is correct
28 Correct 19 ms 9196 KB Output is correct
29 Correct 20 ms 9196 KB Output is correct
30 Correct 19 ms 9196 KB Output is correct
31 Correct 42 ms 10604 KB Output is correct
32 Correct 44 ms 10732 KB Output is correct
33 Correct 51 ms 10604 KB Output is correct
34 Correct 45 ms 10732 KB Output is correct
35 Correct 43 ms 10604 KB Output is correct
36 Correct 46 ms 10732 KB Output is correct
37 Correct 46 ms 10604 KB Output is correct
38 Correct 47 ms 10604 KB Output is correct
39 Correct 46 ms 10732 KB Output is correct
40 Correct 47 ms 10860 KB Output is correct
41 Correct 18 ms 9196 KB Output is correct
42 Correct 21 ms 9324 KB Output is correct
43 Correct 22 ms 9324 KB Output is correct
44 Correct 19 ms 9196 KB Output is correct
45 Correct 21 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 20 ms 9196 KB Output is correct
50 Correct 19 ms 9324 KB Output is correct
51 Correct 46 ms 10092 KB Output is correct
52 Correct 50 ms 9964 KB Output is correct
53 Correct 47 ms 10220 KB Output is correct
54 Correct 48 ms 9964 KB Output is correct
55 Correct 45 ms 10092 KB Output is correct
56 Correct 445 ms 39788 KB Output is correct
57 Correct 430 ms 39660 KB Output is correct
58 Correct 412 ms 38264 KB Output is correct
59 Correct 429 ms 38636 KB Output is correct
60 Correct 448 ms 40556 KB Output is correct