답안 #1092892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092892 2024-09-25T09:51:43 Z MrDogMeat Mountains (NOI20_mountains) C++17
100 / 100
125 ms 14328 KB
#include<bits/stdc++.h>

using namespace std;

using i64 = long long;

const int MAXN = 3e5 + 5;

struct BIT {
    int N, a[MAXN];

    void init(int _N) {
        N = _N;
        memset(a, 0, sizeof a);
    }

    void update(int p, int v) {
        for(; p <= N; p += p&-p) a[p] += v;
    }

    int get_sum(int p) {
        int s = 0;
        for(; p > 0; p -= p&-p) s += a[p];
        return s;
    }

    int get_sum(int l, int r) {
        return (get_sum(r) - get_sum(l - 1));
    }
};

///input
int N;
i64 H[MAXN];

///solution
int L[MAXN], R[MAXN];
BIT tree;

void solution() {
    cin >> N;
    vector<i64> zip;
    for(int i = 1; i <= N; i++)
    {
        cin >> H[i];
        zip.push_back(H[i]);
    }

    sort(zip.begin(), zip.end());
    zip.erase(unique(zip.begin(), zip.end()), zip.end());
    for(int i = 1; i <= N; i++)
    {
        H[i] = lower_bound(zip.begin(), zip.end(), H[i]) - zip.begin() + 1;
    }

    tree.init(N);
    for(int i = 1; i <= N; i++)
    {
        L[i] = tree.get_sum(1, H[i] - 1);
        tree.update(H[i], 1);
    }
    tree.init(N);
    for(int i = N; i > 0; i--)
    {
        R[i] = tree.get_sum(1, H[i] - 1);
        tree.update(H[i], 1);
    }

    i64 Ans = 0;
    for(int i = 1; i <= N; i++)
    {
        Ans += 1LL*L[i]*R[i];
    }

    cout << Ans;
}

#define FILE "C"
int main() {
    if(fopen(FILE".inp","r")) {
        freopen(FILE".inp","r",stdin);
        freopen(FILE".out","w",stdout);
    }
    cin.tie(nullptr) -> ios_base::sync_with_stdio(false);

    solution();

    return 0;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(FILE".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(FILE".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3676 KB Output is correct
2 Correct 65 ms 14328 KB Output is correct
3 Correct 58 ms 14280 KB Output is correct
4 Correct 61 ms 14300 KB Output is correct
5 Correct 59 ms 14272 KB Output is correct
6 Correct 60 ms 14280 KB Output is correct
7 Correct 60 ms 14280 KB Output is correct
8 Correct 67 ms 14268 KB Output is correct
9 Correct 63 ms 14272 KB Output is correct
10 Correct 59 ms 14276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 9252 KB Output is correct
2 Correct 40 ms 9160 KB Output is correct
3 Correct 43 ms 9380 KB Output is correct
4 Correct 40 ms 9148 KB Output is correct
5 Correct 47 ms 9152 KB Output is correct
6 Correct 39 ms 9312 KB Output is correct
7 Correct 48 ms 9272 KB Output is correct
8 Correct 35 ms 9156 KB Output is correct
9 Correct 35 ms 9160 KB Output is correct
10 Correct 1 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 9252 KB Output is correct
2 Correct 40 ms 9160 KB Output is correct
3 Correct 43 ms 9380 KB Output is correct
4 Correct 40 ms 9148 KB Output is correct
5 Correct 47 ms 9152 KB Output is correct
6 Correct 39 ms 9312 KB Output is correct
7 Correct 48 ms 9272 KB Output is correct
8 Correct 35 ms 9156 KB Output is correct
9 Correct 35 ms 9160 KB Output is correct
10 Correct 1 ms 3676 KB Output is correct
11 Correct 50 ms 9424 KB Output is correct
12 Correct 51 ms 9488 KB Output is correct
13 Correct 48 ms 9404 KB Output is correct
14 Correct 48 ms 9408 KB Output is correct
15 Correct 49 ms 9616 KB Output is correct
16 Correct 50 ms 9428 KB Output is correct
17 Correct 49 ms 9500 KB Output is correct
18 Correct 40 ms 9408 KB Output is correct
19 Correct 35 ms 9416 KB Output is correct
20 Correct 1 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 1 ms 3676 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 3680 KB Output is correct
5 Correct 1 ms 3680 KB Output is correct
6 Correct 1 ms 3712 KB Output is correct
7 Correct 1 ms 3676 KB Output is correct
8 Correct 1 ms 3676 KB Output is correct
9 Correct 1 ms 3680 KB Output is correct
10 Correct 1 ms 3680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 1 ms 3676 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 3680 KB Output is correct
5 Correct 1 ms 3680 KB Output is correct
6 Correct 1 ms 3712 KB Output is correct
7 Correct 1 ms 3676 KB Output is correct
8 Correct 1 ms 3676 KB Output is correct
9 Correct 1 ms 3680 KB Output is correct
10 Correct 1 ms 3680 KB Output is correct
11 Correct 4 ms 3932 KB Output is correct
12 Correct 4 ms 3932 KB Output is correct
13 Correct 4 ms 3932 KB Output is correct
14 Correct 4 ms 3936 KB Output is correct
15 Correct 4 ms 3936 KB Output is correct
16 Correct 4 ms 3936 KB Output is correct
17 Correct 4 ms 3936 KB Output is correct
18 Correct 4 ms 3936 KB Output is correct
19 Correct 4 ms 3932 KB Output is correct
20 Correct 1 ms 3672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 9252 KB Output is correct
2 Correct 40 ms 9160 KB Output is correct
3 Correct 43 ms 9380 KB Output is correct
4 Correct 40 ms 9148 KB Output is correct
5 Correct 47 ms 9152 KB Output is correct
6 Correct 39 ms 9312 KB Output is correct
7 Correct 48 ms 9272 KB Output is correct
8 Correct 35 ms 9156 KB Output is correct
9 Correct 35 ms 9160 KB Output is correct
10 Correct 1 ms 3676 KB Output is correct
11 Correct 50 ms 9424 KB Output is correct
12 Correct 51 ms 9488 KB Output is correct
13 Correct 48 ms 9404 KB Output is correct
14 Correct 48 ms 9408 KB Output is correct
15 Correct 49 ms 9616 KB Output is correct
16 Correct 50 ms 9428 KB Output is correct
17 Correct 49 ms 9500 KB Output is correct
18 Correct 40 ms 9408 KB Output is correct
19 Correct 35 ms 9416 KB Output is correct
20 Correct 1 ms 3676 KB Output is correct
21 Correct 95 ms 10436 KB Output is correct
22 Correct 93 ms 10428 KB Output is correct
23 Correct 92 ms 10440 KB Output is correct
24 Correct 97 ms 10348 KB Output is correct
25 Correct 95 ms 10352 KB Output is correct
26 Correct 92 ms 10428 KB Output is correct
27 Correct 96 ms 10428 KB Output is correct
28 Correct 43 ms 10428 KB Output is correct
29 Correct 41 ms 10428 KB Output is correct
30 Correct 1 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3676 KB Output is correct
2 Correct 65 ms 14328 KB Output is correct
3 Correct 58 ms 14280 KB Output is correct
4 Correct 61 ms 14300 KB Output is correct
5 Correct 59 ms 14272 KB Output is correct
6 Correct 60 ms 14280 KB Output is correct
7 Correct 60 ms 14280 KB Output is correct
8 Correct 67 ms 14268 KB Output is correct
9 Correct 63 ms 14272 KB Output is correct
10 Correct 59 ms 14276 KB Output is correct
11 Correct 41 ms 9252 KB Output is correct
12 Correct 40 ms 9160 KB Output is correct
13 Correct 43 ms 9380 KB Output is correct
14 Correct 40 ms 9148 KB Output is correct
15 Correct 47 ms 9152 KB Output is correct
16 Correct 39 ms 9312 KB Output is correct
17 Correct 48 ms 9272 KB Output is correct
18 Correct 35 ms 9156 KB Output is correct
19 Correct 35 ms 9160 KB Output is correct
20 Correct 1 ms 3676 KB Output is correct
21 Correct 50 ms 9424 KB Output is correct
22 Correct 51 ms 9488 KB Output is correct
23 Correct 48 ms 9404 KB Output is correct
24 Correct 48 ms 9408 KB Output is correct
25 Correct 49 ms 9616 KB Output is correct
26 Correct 50 ms 9428 KB Output is correct
27 Correct 49 ms 9500 KB Output is correct
28 Correct 40 ms 9408 KB Output is correct
29 Correct 35 ms 9416 KB Output is correct
30 Correct 1 ms 3676 KB Output is correct
31 Correct 1 ms 3672 KB Output is correct
32 Correct 1 ms 3676 KB Output is correct
33 Correct 1 ms 3676 KB Output is correct
34 Correct 1 ms 3680 KB Output is correct
35 Correct 1 ms 3680 KB Output is correct
36 Correct 1 ms 3712 KB Output is correct
37 Correct 1 ms 3676 KB Output is correct
38 Correct 1 ms 3676 KB Output is correct
39 Correct 1 ms 3680 KB Output is correct
40 Correct 1 ms 3680 KB Output is correct
41 Correct 4 ms 3932 KB Output is correct
42 Correct 4 ms 3932 KB Output is correct
43 Correct 4 ms 3932 KB Output is correct
44 Correct 4 ms 3936 KB Output is correct
45 Correct 4 ms 3936 KB Output is correct
46 Correct 4 ms 3936 KB Output is correct
47 Correct 4 ms 3936 KB Output is correct
48 Correct 4 ms 3936 KB Output is correct
49 Correct 4 ms 3932 KB Output is correct
50 Correct 1 ms 3672 KB Output is correct
51 Correct 95 ms 10436 KB Output is correct
52 Correct 93 ms 10428 KB Output is correct
53 Correct 92 ms 10440 KB Output is correct
54 Correct 97 ms 10348 KB Output is correct
55 Correct 95 ms 10352 KB Output is correct
56 Correct 92 ms 10428 KB Output is correct
57 Correct 96 ms 10428 KB Output is correct
58 Correct 43 ms 10428 KB Output is correct
59 Correct 41 ms 10428 KB Output is correct
60 Correct 1 ms 3676 KB Output is correct
61 Correct 125 ms 14100 KB Output is correct
62 Correct 123 ms 14272 KB Output is correct
63 Correct 118 ms 14264 KB Output is correct
64 Correct 116 ms 14156 KB Output is correct
65 Correct 122 ms 14140 KB Output is correct
66 Correct 120 ms 14272 KB Output is correct
67 Correct 118 ms 14208 KB Output is correct
68 Correct 115 ms 14272 KB Output is correct
69 Correct 104 ms 10428 KB Output is correct
70 Correct 1 ms 3672 KB Output is correct