답안 #336418

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336418 2020-12-15T09:36:14 Z ncduy0303 Pilot (NOI19_pilot) C++17
78 / 100
60 ms 12012 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]] += (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();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8300 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 8 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 8300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8300 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 8 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 8300 KB Output is correct
11 Correct 7 ms 8192 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 ms 8172 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8300 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 8 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 8300 KB Output is correct
11 Correct 7 ms 8192 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 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 8108 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 7 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8300 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 8 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 8300 KB Output is correct
11 Correct 7 ms 8192 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 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 8108 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 8172 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 9 ms 8172 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 9836 KB Output is correct
2 Correct 22 ms 9964 KB Output is correct
3 Correct 20 ms 9836 KB Output is correct
4 Correct 21 ms 9836 KB Output is correct
5 Correct 19 ms 9836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 11756 KB Output is correct
2 Correct 46 ms 11756 KB Output is correct
3 Correct 48 ms 11796 KB Output is correct
4 Correct 45 ms 11884 KB Output is correct
5 Correct 44 ms 11756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 11904 KB Output is correct
2 Correct 60 ms 12012 KB Output is correct
3 Correct 57 ms 11872 KB Output is correct
4 Correct 47 ms 12012 KB Output is correct
5 Correct 49 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8300 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 8 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 8300 KB Output is correct
11 Correct 19 ms 9836 KB Output is correct
12 Correct 22 ms 9964 KB Output is correct
13 Correct 20 ms 9836 KB Output is correct
14 Correct 21 ms 9836 KB Output is correct
15 Correct 19 ms 9836 KB Output is correct
16 Correct 19 ms 9836 KB Output is correct
17 Correct 26 ms 9964 KB Output is correct
18 Correct 25 ms 9964 KB Output is correct
19 Correct 19 ms 9836 KB Output is correct
20 Correct 22 ms 9964 KB Output is correct
21 Correct 19 ms 9836 KB Output is correct
22 Correct 21 ms 9964 KB Output is correct
23 Correct 20 ms 9964 KB Output is correct
24 Correct 25 ms 9836 KB Output is correct
25 Correct 22 ms 9860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8300 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 8 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 8300 KB Output is correct
11 Correct 7 ms 8192 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 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 8108 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 8172 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 9 ms 8172 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
26 Correct 19 ms 9836 KB Output is correct
27 Correct 22 ms 9964 KB Output is correct
28 Correct 20 ms 9836 KB Output is correct
29 Correct 21 ms 9836 KB Output is correct
30 Correct 19 ms 9836 KB Output is correct
31 Correct 49 ms 11756 KB Output is correct
32 Correct 46 ms 11756 KB Output is correct
33 Correct 48 ms 11796 KB Output is correct
34 Correct 45 ms 11884 KB Output is correct
35 Correct 44 ms 11756 KB Output is correct
36 Correct 47 ms 11904 KB Output is correct
37 Correct 60 ms 12012 KB Output is correct
38 Correct 57 ms 11872 KB Output is correct
39 Correct 47 ms 12012 KB Output is correct
40 Correct 49 ms 12012 KB Output is correct
41 Correct 19 ms 9836 KB Output is correct
42 Correct 26 ms 9964 KB Output is correct
43 Correct 25 ms 9964 KB Output is correct
44 Correct 19 ms 9836 KB Output is correct
45 Correct 22 ms 9964 KB Output is correct
46 Correct 19 ms 9836 KB Output is correct
47 Correct 21 ms 9964 KB Output is correct
48 Correct 20 ms 9964 KB Output is correct
49 Correct 25 ms 9836 KB Output is correct
50 Correct 22 ms 9860 KB Output is correct
51 Correct 46 ms 11244 KB Output is correct
52 Correct 50 ms 11244 KB Output is correct
53 Correct 47 ms 11244 KB Output is correct
54 Correct 50 ms 11244 KB Output is correct
55 Incorrect 48 ms 11244 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8300 KB Output is correct
2 Correct 7 ms 8172 KB Output is correct
3 Correct 8 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 8300 KB Output is correct
11 Correct 7 ms 8192 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 8 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 8108 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 8172 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 9 ms 8172 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
26 Correct 19 ms 9836 KB Output is correct
27 Correct 22 ms 9964 KB Output is correct
28 Correct 20 ms 9836 KB Output is correct
29 Correct 21 ms 9836 KB Output is correct
30 Correct 19 ms 9836 KB Output is correct
31 Correct 49 ms 11756 KB Output is correct
32 Correct 46 ms 11756 KB Output is correct
33 Correct 48 ms 11796 KB Output is correct
34 Correct 45 ms 11884 KB Output is correct
35 Correct 44 ms 11756 KB Output is correct
36 Correct 47 ms 11904 KB Output is correct
37 Correct 60 ms 12012 KB Output is correct
38 Correct 57 ms 11872 KB Output is correct
39 Correct 47 ms 12012 KB Output is correct
40 Correct 49 ms 12012 KB Output is correct
41 Correct 19 ms 9836 KB Output is correct
42 Correct 26 ms 9964 KB Output is correct
43 Correct 25 ms 9964 KB Output is correct
44 Correct 19 ms 9836 KB Output is correct
45 Correct 22 ms 9964 KB Output is correct
46 Correct 19 ms 9836 KB Output is correct
47 Correct 21 ms 9964 KB Output is correct
48 Correct 20 ms 9964 KB Output is correct
49 Correct 25 ms 9836 KB Output is correct
50 Correct 22 ms 9860 KB Output is correct
51 Correct 46 ms 11244 KB Output is correct
52 Correct 50 ms 11244 KB Output is correct
53 Correct 47 ms 11244 KB Output is correct
54 Correct 50 ms 11244 KB Output is correct
55 Incorrect 48 ms 11244 KB Output isn't correct