답안 #1000759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1000759 2024-06-18T08:25:59 Z fryingduc Mountains (NOI20_mountains) C++17
100 / 100
142 ms 14684 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 3e5 + 6;
int n;
long long a[maxn];
int bit[maxn];
int ord[maxn];

#define gb(x) (x) & (-x)
void update(int x, int val) {
    for(int i = x; i <= n; i += gb(i)) bit[i] += val;
}
int get(int x) {
    int ans = 0;
    for(int i = x; i > 0; i -= gb(i)) ans += bit[i];
    return ans;
}
int get(int l, int r) {
    return get(r) - get(l - 1);
}
void solve() {
    cin >> n;
    vector<long long> vec;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        vec.push_back(a[i]);
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    for(int i = 1; i <= n; ++i) {
        a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin() + 1;
    }
    iota(ord + 1, ord + n + 1, 1);
    sort(ord + 1, ord + n + 1, [](const int &x, const int &y) -> bool {
        return a[x] < a[y];
    });
    long long ans = 0;
    for(int i = 1; i <= n; ++i) {
        int cur = 0;
        while(i + cur <= n and a[ord[i]] == a[ord[i + cur]]) ++cur;
        for(int j = i; j < i + cur; ++j) {
            int x = get(ord[j] - 1), y = get(ord[j] + 1, n);
            ans = ans + 1ll * x * y;
            
        }
        for(int j = i; j < i + cur; ++j) {
            update(ord[j], 1);
        }
        i = i + cur - 1;
    }
    cout << ans;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 67 ms 12996 KB Output is correct
3 Correct 66 ms 13084 KB Output is correct
4 Correct 65 ms 13244 KB Output is correct
5 Correct 102 ms 12988 KB Output is correct
6 Correct 62 ms 13628 KB Output is correct
7 Correct 63 ms 13764 KB Output is correct
8 Correct 69 ms 13140 KB Output is correct
9 Correct 63 ms 13512 KB Output is correct
10 Correct 64 ms 12996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 8392 KB Output is correct
2 Correct 39 ms 9156 KB Output is correct
3 Correct 39 ms 9168 KB Output is correct
4 Correct 39 ms 8644 KB Output is correct
5 Correct 39 ms 8140 KB Output is correct
6 Correct 37 ms 8912 KB Output is correct
7 Correct 38 ms 8388 KB Output is correct
8 Correct 30 ms 8932 KB Output is correct
9 Correct 30 ms 9668 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 8392 KB Output is correct
2 Correct 39 ms 9156 KB Output is correct
3 Correct 39 ms 9168 KB Output is correct
4 Correct 39 ms 8644 KB Output is correct
5 Correct 39 ms 8140 KB Output is correct
6 Correct 37 ms 8912 KB Output is correct
7 Correct 38 ms 8388 KB Output is correct
8 Correct 30 ms 8932 KB Output is correct
9 Correct 30 ms 9668 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 63 ms 9260 KB Output is correct
12 Correct 65 ms 8896 KB Output is correct
13 Correct 63 ms 8400 KB Output is correct
14 Correct 62 ms 8900 KB Output is correct
15 Correct 63 ms 9916 KB Output is correct
16 Correct 63 ms 9576 KB Output is correct
17 Correct 75 ms 9848 KB Output is correct
18 Correct 30 ms 8976 KB Output is correct
19 Correct 32 ms 8656 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 4 ms 2904 KB Output is correct
12 Correct 4 ms 2908 KB Output is correct
13 Correct 4 ms 2908 KB Output is correct
14 Correct 5 ms 2776 KB Output is correct
15 Correct 4 ms 2900 KB Output is correct
16 Correct 4 ms 2908 KB Output is correct
17 Correct 4 ms 2908 KB Output is correct
18 Correct 4 ms 2896 KB Output is correct
19 Correct 3 ms 2648 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 8392 KB Output is correct
2 Correct 39 ms 9156 KB Output is correct
3 Correct 39 ms 9168 KB Output is correct
4 Correct 39 ms 8644 KB Output is correct
5 Correct 39 ms 8140 KB Output is correct
6 Correct 37 ms 8912 KB Output is correct
7 Correct 38 ms 8388 KB Output is correct
8 Correct 30 ms 8932 KB Output is correct
9 Correct 30 ms 9668 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 63 ms 9260 KB Output is correct
12 Correct 65 ms 8896 KB Output is correct
13 Correct 63 ms 8400 KB Output is correct
14 Correct 62 ms 8900 KB Output is correct
15 Correct 63 ms 9916 KB Output is correct
16 Correct 63 ms 9576 KB Output is correct
17 Correct 75 ms 9848 KB Output is correct
18 Correct 30 ms 8976 KB Output is correct
19 Correct 32 ms 8656 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 112 ms 9200 KB Output is correct
22 Correct 111 ms 10688 KB Output is correct
23 Correct 109 ms 10920 KB Output is correct
24 Correct 107 ms 9184 KB Output is correct
25 Correct 109 ms 9404 KB Output is correct
26 Correct 110 ms 9660 KB Output is correct
27 Correct 114 ms 10116 KB Output is correct
28 Correct 46 ms 10180 KB Output is correct
29 Correct 49 ms 10228 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 67 ms 12996 KB Output is correct
3 Correct 66 ms 13084 KB Output is correct
4 Correct 65 ms 13244 KB Output is correct
5 Correct 102 ms 12988 KB Output is correct
6 Correct 62 ms 13628 KB Output is correct
7 Correct 63 ms 13764 KB Output is correct
8 Correct 69 ms 13140 KB Output is correct
9 Correct 63 ms 13512 KB Output is correct
10 Correct 64 ms 12996 KB Output is correct
11 Correct 38 ms 8392 KB Output is correct
12 Correct 39 ms 9156 KB Output is correct
13 Correct 39 ms 9168 KB Output is correct
14 Correct 39 ms 8644 KB Output is correct
15 Correct 39 ms 8140 KB Output is correct
16 Correct 37 ms 8912 KB Output is correct
17 Correct 38 ms 8388 KB Output is correct
18 Correct 30 ms 8932 KB Output is correct
19 Correct 30 ms 9668 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 63 ms 9260 KB Output is correct
22 Correct 65 ms 8896 KB Output is correct
23 Correct 63 ms 8400 KB Output is correct
24 Correct 62 ms 8900 KB Output is correct
25 Correct 63 ms 9916 KB Output is correct
26 Correct 63 ms 9576 KB Output is correct
27 Correct 75 ms 9848 KB Output is correct
28 Correct 30 ms 8976 KB Output is correct
29 Correct 32 ms 8656 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 4 ms 2904 KB Output is correct
42 Correct 4 ms 2908 KB Output is correct
43 Correct 4 ms 2908 KB Output is correct
44 Correct 5 ms 2776 KB Output is correct
45 Correct 4 ms 2900 KB Output is correct
46 Correct 4 ms 2908 KB Output is correct
47 Correct 4 ms 2908 KB Output is correct
48 Correct 4 ms 2896 KB Output is correct
49 Correct 3 ms 2648 KB Output is correct
50 Correct 0 ms 2396 KB Output is correct
51 Correct 112 ms 9200 KB Output is correct
52 Correct 111 ms 10688 KB Output is correct
53 Correct 109 ms 10920 KB Output is correct
54 Correct 107 ms 9184 KB Output is correct
55 Correct 109 ms 9404 KB Output is correct
56 Correct 110 ms 9660 KB Output is correct
57 Correct 114 ms 10116 KB Output is correct
58 Correct 46 ms 10180 KB Output is correct
59 Correct 49 ms 10228 KB Output is correct
60 Correct 1 ms 2392 KB Output is correct
61 Correct 131 ms 14684 KB Output is correct
62 Correct 129 ms 13056 KB Output is correct
63 Correct 134 ms 14464 KB Output is correct
64 Correct 128 ms 14016 KB Output is correct
65 Correct 134 ms 12992 KB Output is correct
66 Correct 130 ms 14436 KB Output is correct
67 Correct 142 ms 13100 KB Output is correct
68 Correct 128 ms 14412 KB Output is correct
69 Correct 110 ms 10548 KB Output is correct
70 Correct 0 ms 2392 KB Output is correct