답안 #478190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478190 2021-10-06T11:01:36 Z blue Mountains (NOI20_mountains) C++17
100 / 100
156 ms 16476 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxN = 300'000;
long long H[1+maxN];

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

    int N;
    cin >> N;

    for(int i = 1; i <= N; i++) cin >> H[i];

    vector<int> ind(N);
    for(int i = 1; i <= N; i++) ind[i-1] = i;

    sort(ind.begin(), ind.end(), [] (int p, int q)
    {
        if(H[p] == H[q]) return p > q;
        return H[p] < H[q];
    });

    vector<long long> lft(1+N, 0), rgt(1+N, 0);

    vector<int> BIT(1+N, 0);
    for(int i: ind)
    {
        for(int j = i; j <= N; j += j&-j)
            BIT[j]++;

        for(int j = i-1; j >= 1; j -= j&-j)
            lft[i] += BIT[j];
    }
    // cerr << "check\n";

    BIT = vector<int>(1+N, 0);
    sort(ind.begin(), ind.end(), [] (int p, int q)
    {
        if(H[p] == H[q]) return p < q;
        return H[p] < H[q];
    });

    // cerr << "check\n";

    for(int i: ind)
    {
        for(int j = i; j <= N; j += j&-j)
            BIT[j]++;

        for(int j = N; j >= 1; j -= j&-j)
            rgt[i] += BIT[j];

        for(int j = i; j >= 1; j -= j&-j)
            rgt[i] -= BIT[j];
    }

    // for(int i = 1; i <= N; i++) cerr << lft[i] << ' ';
    // cerr << '\n';

    long long ans = 0;
    for(int i = 1; i <= N; i++) ans += lft[i] * rgt[i];

    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 102 ms 16336 KB Output is correct
3 Correct 103 ms 16412 KB Output is correct
4 Correct 102 ms 16272 KB Output is correct
5 Correct 104 ms 16324 KB Output is correct
6 Correct 96 ms 16256 KB Output is correct
7 Correct 99 ms 16324 KB Output is correct
8 Correct 93 ms 16324 KB Output is correct
9 Correct 105 ms 16476 KB Output is correct
10 Correct 102 ms 16372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 10852 KB Output is correct
2 Correct 107 ms 10828 KB Output is correct
3 Correct 95 ms 10856 KB Output is correct
4 Correct 107 ms 10820 KB Output is correct
5 Correct 90 ms 10852 KB Output is correct
6 Correct 110 ms 10868 KB Output is correct
7 Correct 112 ms 10764 KB Output is correct
8 Correct 129 ms 10868 KB Output is correct
9 Correct 113 ms 10884 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 10852 KB Output is correct
2 Correct 107 ms 10828 KB Output is correct
3 Correct 95 ms 10856 KB Output is correct
4 Correct 107 ms 10820 KB Output is correct
5 Correct 90 ms 10852 KB Output is correct
6 Correct 110 ms 10868 KB Output is correct
7 Correct 112 ms 10764 KB Output is correct
8 Correct 129 ms 10868 KB Output is correct
9 Correct 113 ms 10884 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 114 ms 10872 KB Output is correct
12 Correct 115 ms 10840 KB Output is correct
13 Correct 119 ms 10876 KB Output is correct
14 Correct 111 ms 10752 KB Output is correct
15 Correct 131 ms 10872 KB Output is correct
16 Correct 124 ms 10764 KB Output is correct
17 Correct 124 ms 10820 KB Output is correct
18 Correct 81 ms 10820 KB Output is correct
19 Correct 82 ms 10820 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 4 ms 848 KB Output is correct
12 Correct 4 ms 848 KB Output is correct
13 Correct 4 ms 848 KB Output is correct
14 Correct 4 ms 848 KB Output is correct
15 Correct 5 ms 848 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 844 KB Output is correct
19 Correct 3 ms 592 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 10852 KB Output is correct
2 Correct 107 ms 10828 KB Output is correct
3 Correct 95 ms 10856 KB Output is correct
4 Correct 107 ms 10820 KB Output is correct
5 Correct 90 ms 10852 KB Output is correct
6 Correct 110 ms 10868 KB Output is correct
7 Correct 112 ms 10764 KB Output is correct
8 Correct 129 ms 10868 KB Output is correct
9 Correct 113 ms 10884 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 114 ms 10872 KB Output is correct
12 Correct 115 ms 10840 KB Output is correct
13 Correct 119 ms 10876 KB Output is correct
14 Correct 111 ms 10752 KB Output is correct
15 Correct 131 ms 10872 KB Output is correct
16 Correct 124 ms 10764 KB Output is correct
17 Correct 124 ms 10820 KB Output is correct
18 Correct 81 ms 10820 KB Output is correct
19 Correct 82 ms 10820 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 128 ms 10872 KB Output is correct
22 Correct 132 ms 10868 KB Output is correct
23 Correct 129 ms 10940 KB Output is correct
24 Correct 131 ms 10756 KB Output is correct
25 Correct 115 ms 10868 KB Output is correct
26 Correct 123 ms 10824 KB Output is correct
27 Correct 121 ms 10820 KB Output is correct
28 Correct 79 ms 10820 KB Output is correct
29 Correct 72 ms 10816 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 102 ms 16336 KB Output is correct
3 Correct 103 ms 16412 KB Output is correct
4 Correct 102 ms 16272 KB Output is correct
5 Correct 104 ms 16324 KB Output is correct
6 Correct 96 ms 16256 KB Output is correct
7 Correct 99 ms 16324 KB Output is correct
8 Correct 93 ms 16324 KB Output is correct
9 Correct 105 ms 16476 KB Output is correct
10 Correct 102 ms 16372 KB Output is correct
11 Correct 91 ms 10852 KB Output is correct
12 Correct 107 ms 10828 KB Output is correct
13 Correct 95 ms 10856 KB Output is correct
14 Correct 107 ms 10820 KB Output is correct
15 Correct 90 ms 10852 KB Output is correct
16 Correct 110 ms 10868 KB Output is correct
17 Correct 112 ms 10764 KB Output is correct
18 Correct 129 ms 10868 KB Output is correct
19 Correct 113 ms 10884 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 114 ms 10872 KB Output is correct
22 Correct 115 ms 10840 KB Output is correct
23 Correct 119 ms 10876 KB Output is correct
24 Correct 111 ms 10752 KB Output is correct
25 Correct 131 ms 10872 KB Output is correct
26 Correct 124 ms 10764 KB Output is correct
27 Correct 124 ms 10820 KB Output is correct
28 Correct 81 ms 10820 KB Output is correct
29 Correct 82 ms 10820 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 208 KB Output is correct
41 Correct 4 ms 848 KB Output is correct
42 Correct 4 ms 848 KB Output is correct
43 Correct 4 ms 848 KB Output is correct
44 Correct 4 ms 848 KB Output is correct
45 Correct 5 ms 848 KB Output is correct
46 Correct 4 ms 844 KB Output is correct
47 Correct 4 ms 848 KB Output is correct
48 Correct 4 ms 844 KB Output is correct
49 Correct 3 ms 592 KB Output is correct
50 Correct 1 ms 208 KB Output is correct
51 Correct 128 ms 10872 KB Output is correct
52 Correct 132 ms 10868 KB Output is correct
53 Correct 129 ms 10940 KB Output is correct
54 Correct 131 ms 10756 KB Output is correct
55 Correct 115 ms 10868 KB Output is correct
56 Correct 123 ms 10824 KB Output is correct
57 Correct 121 ms 10820 KB Output is correct
58 Correct 79 ms 10820 KB Output is correct
59 Correct 72 ms 10816 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 151 ms 16324 KB Output is correct
62 Correct 139 ms 16304 KB Output is correct
63 Correct 138 ms 16388 KB Output is correct
64 Correct 148 ms 16384 KB Output is correct
65 Correct 156 ms 16420 KB Output is correct
66 Correct 140 ms 16328 KB Output is correct
67 Correct 144 ms 16368 KB Output is correct
68 Correct 155 ms 16452 KB Output is correct
69 Correct 117 ms 12708 KB Output is correct
70 Correct 0 ms 208 KB Output is correct