답안 #909428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909428 2024-01-17T08:06:12 Z LOLOLO Pilot (NOI19_pilot) C++17
100 / 100
666 ms 58228 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 1e6 + 100;
ll pr[N], l[N], r[N];
int a[N], b[N], n, c[N], d[N], sz = 0;

void compress() {
    int lst = 0;
    for (int i = 1; i <= n; i++) {
        if (b[i] != lst) {
            lst = b[i];
            sz++;
            b[sz] = lst;
        }
    }

    for (int i = 1; i <= n; i++) {
        c[i] = lower_bound(b, b + 1 + sz, a[i]) - b;
    }
}

ll solve() {
    int m;
    cin >> n >> m;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }

    sort(b + 1, b + 1 + n);
    compress();

    a[0] = a[n + 1] = 1e9 + 1;
    stack <int> st;

    for (int i = 0; i <= n; i++) {
        while (sz(st) && a[i] > a[st.top()]) {
            st.pop();
        }

        if (sz(st)) {
            l[i] = st.top() + 1;
        }

        st.push(i);
    }

    while (sz(st))
        st.pop();

    for (int i = n + 1; i >= 1; i--) {
        while (sz(st) && a[i] >= a[st.top()]) {
            st.pop();
        }

        if (sz(st)) {
            r[i] = st.top() - 1;
        }

        st.push(i);
    }

    for (ll i = 1; i <= n; i++) {
        pr[c[i]] += (i - l[i] + 1) * (r[i] - i + 1);
    }

    for (int i = 1; i <= n; i++) {
        pr[i] += pr[i - 1];
    }

    while (m--) {
        int x;
        cin >> x;
        x = upper_bound(b, b + 1 + sz, x) - b - 1;
        cout << pr[x] << '\n';
    }

    return 0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
    //cin >> t;

    while (t--) {
        solve();
        //cout << solve() << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14840 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14784 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 3 ms 14684 KB Output is correct
7 Correct 3 ms 14680 KB Output is correct
8 Correct 4 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14840 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14784 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 3 ms 14684 KB Output is correct
7 Correct 3 ms 14680 KB Output is correct
8 Correct 4 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 3 ms 14680 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 3 ms 14684 KB Output is correct
14 Correct 3 ms 14684 KB Output is correct
15 Correct 3 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14840 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14784 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 3 ms 14684 KB Output is correct
7 Correct 3 ms 14680 KB Output is correct
8 Correct 4 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 3 ms 14680 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 3 ms 14684 KB Output is correct
14 Correct 3 ms 14684 KB Output is correct
15 Correct 3 ms 14680 KB Output is correct
16 Correct 3 ms 14684 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 3 ms 14684 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14840 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14784 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 3 ms 14684 KB Output is correct
7 Correct 3 ms 14680 KB Output is correct
8 Correct 4 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 3 ms 14680 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 3 ms 14684 KB Output is correct
14 Correct 3 ms 14684 KB Output is correct
15 Correct 3 ms 14680 KB Output is correct
16 Correct 3 ms 14684 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 3 ms 14684 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 3 ms 14684 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
23 Correct 3 ms 14684 KB Output is correct
24 Correct 3 ms 14824 KB Output is correct
25 Correct 3 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 17232 KB Output is correct
2 Correct 27 ms 17484 KB Output is correct
3 Correct 25 ms 17240 KB Output is correct
4 Correct 26 ms 15188 KB Output is correct
5 Correct 25 ms 15316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 19256 KB Output is correct
2 Correct 38 ms 17236 KB Output is correct
3 Correct 37 ms 17196 KB Output is correct
4 Correct 39 ms 19280 KB Output is correct
5 Correct 35 ms 17024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 19284 KB Output is correct
2 Correct 41 ms 17236 KB Output is correct
3 Correct 38 ms 17232 KB Output is correct
4 Correct 38 ms 19284 KB Output is correct
5 Correct 40 ms 19540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14840 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14784 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 3 ms 14684 KB Output is correct
7 Correct 3 ms 14680 KB Output is correct
8 Correct 4 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 27 ms 17232 KB Output is correct
12 Correct 27 ms 17484 KB Output is correct
13 Correct 25 ms 17240 KB Output is correct
14 Correct 26 ms 15188 KB Output is correct
15 Correct 25 ms 15316 KB Output is correct
16 Correct 25 ms 15184 KB Output is correct
17 Correct 27 ms 17492 KB Output is correct
18 Correct 28 ms 17484 KB Output is correct
19 Correct 26 ms 15192 KB Output is correct
20 Correct 27 ms 17232 KB Output is correct
21 Correct 27 ms 15312 KB Output is correct
22 Correct 28 ms 15196 KB Output is correct
23 Correct 27 ms 17412 KB Output is correct
24 Correct 25 ms 15184 KB Output is correct
25 Correct 26 ms 17384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14840 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14784 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 3 ms 14684 KB Output is correct
7 Correct 3 ms 14680 KB Output is correct
8 Correct 4 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 3 ms 14680 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 3 ms 14684 KB Output is correct
14 Correct 3 ms 14684 KB Output is correct
15 Correct 3 ms 14680 KB Output is correct
16 Correct 3 ms 14684 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 3 ms 14684 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 3 ms 14684 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
23 Correct 3 ms 14684 KB Output is correct
24 Correct 3 ms 14824 KB Output is correct
25 Correct 3 ms 14684 KB Output is correct
26 Correct 27 ms 17232 KB Output is correct
27 Correct 27 ms 17484 KB Output is correct
28 Correct 25 ms 17240 KB Output is correct
29 Correct 26 ms 15188 KB Output is correct
30 Correct 25 ms 15316 KB Output is correct
31 Correct 40 ms 19256 KB Output is correct
32 Correct 38 ms 17236 KB Output is correct
33 Correct 37 ms 17196 KB Output is correct
34 Correct 39 ms 19280 KB Output is correct
35 Correct 35 ms 17024 KB Output is correct
36 Correct 38 ms 19284 KB Output is correct
37 Correct 41 ms 17236 KB Output is correct
38 Correct 38 ms 17232 KB Output is correct
39 Correct 38 ms 19284 KB Output is correct
40 Correct 40 ms 19540 KB Output is correct
41 Correct 25 ms 15184 KB Output is correct
42 Correct 27 ms 17492 KB Output is correct
43 Correct 28 ms 17484 KB Output is correct
44 Correct 26 ms 15192 KB Output is correct
45 Correct 27 ms 17232 KB Output is correct
46 Correct 27 ms 15312 KB Output is correct
47 Correct 28 ms 15196 KB Output is correct
48 Correct 27 ms 17412 KB Output is correct
49 Correct 25 ms 15184 KB Output is correct
50 Correct 26 ms 17384 KB Output is correct
51 Correct 51 ms 18768 KB Output is correct
52 Correct 50 ms 18572 KB Output is correct
53 Correct 45 ms 18756 KB Output is correct
54 Correct 54 ms 18512 KB Output is correct
55 Correct 47 ms 18772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14840 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14784 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 3 ms 14684 KB Output is correct
7 Correct 3 ms 14680 KB Output is correct
8 Correct 4 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 4 ms 14684 KB Output is correct
11 Correct 3 ms 14680 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 3 ms 14684 KB Output is correct
14 Correct 3 ms 14684 KB Output is correct
15 Correct 3 ms 14680 KB Output is correct
16 Correct 3 ms 14684 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 3 ms 14684 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 3 ms 14684 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
23 Correct 3 ms 14684 KB Output is correct
24 Correct 3 ms 14824 KB Output is correct
25 Correct 3 ms 14684 KB Output is correct
26 Correct 27 ms 17232 KB Output is correct
27 Correct 27 ms 17484 KB Output is correct
28 Correct 25 ms 17240 KB Output is correct
29 Correct 26 ms 15188 KB Output is correct
30 Correct 25 ms 15316 KB Output is correct
31 Correct 40 ms 19256 KB Output is correct
32 Correct 38 ms 17236 KB Output is correct
33 Correct 37 ms 17196 KB Output is correct
34 Correct 39 ms 19280 KB Output is correct
35 Correct 35 ms 17024 KB Output is correct
36 Correct 38 ms 19284 KB Output is correct
37 Correct 41 ms 17236 KB Output is correct
38 Correct 38 ms 17232 KB Output is correct
39 Correct 38 ms 19284 KB Output is correct
40 Correct 40 ms 19540 KB Output is correct
41 Correct 25 ms 15184 KB Output is correct
42 Correct 27 ms 17492 KB Output is correct
43 Correct 28 ms 17484 KB Output is correct
44 Correct 26 ms 15192 KB Output is correct
45 Correct 27 ms 17232 KB Output is correct
46 Correct 27 ms 15312 KB Output is correct
47 Correct 28 ms 15196 KB Output is correct
48 Correct 27 ms 17412 KB Output is correct
49 Correct 25 ms 15184 KB Output is correct
50 Correct 26 ms 17384 KB Output is correct
51 Correct 51 ms 18768 KB Output is correct
52 Correct 50 ms 18572 KB Output is correct
53 Correct 45 ms 18756 KB Output is correct
54 Correct 54 ms 18512 KB Output is correct
55 Correct 47 ms 18772 KB Output is correct
56 Correct 582 ms 58020 KB Output is correct
57 Correct 637 ms 57156 KB Output is correct
58 Correct 546 ms 56344 KB Output is correct
59 Correct 601 ms 56776 KB Output is correct
60 Correct 666 ms 58228 KB Output is correct