답안 #349380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349380 2021-01-17T13:22:55 Z phathnv Mountains (NOI20_mountains) C++11
100 / 100
120 ms 10732 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 3e5 + 1;

struct FenwickTree{
    int d[N];
    void update(int x){
        for(; x < N; x += x & -x)
            d[x]++;
    }
    int get(int x){
        int res = 0;
        for(; x > 0; x -= x & -x)
            res += d[x];
        return res;
    }
    int getRange(int l, int r){
        assert(l <= r);
        return get(r) - get(l - 1);
    }
} bit;

int n, ind[N];
ll a[N];

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

void Solve(){
    for(int i = 1; i <= n; i++)
        ind[i] = i;
    sort(ind + 1, ind + 1 + n, [&](const int &x, const int &y){
            return a[x] < a[y];
         });
    ll res = 0;
    for(int i = 1; i <= n; i++){
        int j = i;
        while (j < n && a[ind[i]] == a[ind[j + 1]])
            j++;
        for(int k = i; k <= j; k++)
            res += (ll) bit.getRange(1, ind[k]) * bit.getRange(ind[k], n);
        for(int k = i; k <= j; k++)
            bit.update(ind[k]);
        i = j;
    }

    cout << res;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ReadInput();
    Solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 81 ms 10604 KB Output is correct
3 Correct 81 ms 10604 KB Output is correct
4 Correct 81 ms 10604 KB Output is correct
5 Correct 80 ms 10604 KB Output is correct
6 Correct 80 ms 10604 KB Output is correct
7 Correct 80 ms 10604 KB Output is correct
8 Correct 78 ms 10732 KB Output is correct
9 Correct 86 ms 10732 KB Output is correct
10 Correct 84 ms 10620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 5612 KB Output is correct
2 Correct 48 ms 5680 KB Output is correct
3 Correct 48 ms 5612 KB Output is correct
4 Correct 48 ms 5612 KB Output is correct
5 Correct 48 ms 5612 KB Output is correct
6 Correct 49 ms 5612 KB Output is correct
7 Correct 49 ms 5612 KB Output is correct
8 Correct 43 ms 5612 KB Output is correct
9 Correct 45 ms 5612 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 5612 KB Output is correct
2 Correct 48 ms 5680 KB Output is correct
3 Correct 48 ms 5612 KB Output is correct
4 Correct 48 ms 5612 KB Output is correct
5 Correct 48 ms 5612 KB Output is correct
6 Correct 49 ms 5612 KB Output is correct
7 Correct 49 ms 5612 KB Output is correct
8 Correct 43 ms 5612 KB Output is correct
9 Correct 45 ms 5612 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 72 ms 5848 KB Output is correct
12 Correct 62 ms 5868 KB Output is correct
13 Correct 61 ms 5868 KB Output is correct
14 Correct 63 ms 5888 KB Output is correct
15 Correct 67 ms 5888 KB Output is correct
16 Correct 61 ms 5868 KB Output is correct
17 Correct 61 ms 5868 KB Output is correct
18 Correct 44 ms 5868 KB Output is correct
19 Correct 44 ms 5996 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 4 ms 748 KB Output is correct
12 Correct 4 ms 748 KB Output is correct
13 Correct 4 ms 748 KB Output is correct
14 Correct 4 ms 748 KB Output is correct
15 Correct 4 ms 748 KB Output is correct
16 Correct 4 ms 748 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 4 ms 748 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 5612 KB Output is correct
2 Correct 48 ms 5680 KB Output is correct
3 Correct 48 ms 5612 KB Output is correct
4 Correct 48 ms 5612 KB Output is correct
5 Correct 48 ms 5612 KB Output is correct
6 Correct 49 ms 5612 KB Output is correct
7 Correct 49 ms 5612 KB Output is correct
8 Correct 43 ms 5612 KB Output is correct
9 Correct 45 ms 5612 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 72 ms 5848 KB Output is correct
12 Correct 62 ms 5868 KB Output is correct
13 Correct 61 ms 5868 KB Output is correct
14 Correct 63 ms 5888 KB Output is correct
15 Correct 67 ms 5888 KB Output is correct
16 Correct 61 ms 5868 KB Output is correct
17 Correct 61 ms 5868 KB Output is correct
18 Correct 44 ms 5868 KB Output is correct
19 Correct 44 ms 5996 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 89 ms 6764 KB Output is correct
22 Correct 89 ms 6836 KB Output is correct
23 Correct 87 ms 6764 KB Output is correct
24 Correct 89 ms 6836 KB Output is correct
25 Correct 90 ms 6764 KB Output is correct
26 Correct 88 ms 6764 KB Output is correct
27 Correct 93 ms 6820 KB Output is correct
28 Correct 55 ms 6764 KB Output is correct
29 Correct 59 ms 6764 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 81 ms 10604 KB Output is correct
3 Correct 81 ms 10604 KB Output is correct
4 Correct 81 ms 10604 KB Output is correct
5 Correct 80 ms 10604 KB Output is correct
6 Correct 80 ms 10604 KB Output is correct
7 Correct 80 ms 10604 KB Output is correct
8 Correct 78 ms 10732 KB Output is correct
9 Correct 86 ms 10732 KB Output is correct
10 Correct 84 ms 10620 KB Output is correct
11 Correct 49 ms 5612 KB Output is correct
12 Correct 48 ms 5680 KB Output is correct
13 Correct 48 ms 5612 KB Output is correct
14 Correct 48 ms 5612 KB Output is correct
15 Correct 48 ms 5612 KB Output is correct
16 Correct 49 ms 5612 KB Output is correct
17 Correct 49 ms 5612 KB Output is correct
18 Correct 43 ms 5612 KB Output is correct
19 Correct 45 ms 5612 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 72 ms 5848 KB Output is correct
22 Correct 62 ms 5868 KB Output is correct
23 Correct 61 ms 5868 KB Output is correct
24 Correct 63 ms 5888 KB Output is correct
25 Correct 67 ms 5888 KB Output is correct
26 Correct 61 ms 5868 KB Output is correct
27 Correct 61 ms 5868 KB Output is correct
28 Correct 44 ms 5868 KB Output is correct
29 Correct 44 ms 5996 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 4 ms 748 KB Output is correct
42 Correct 4 ms 748 KB Output is correct
43 Correct 4 ms 748 KB Output is correct
44 Correct 4 ms 748 KB Output is correct
45 Correct 4 ms 748 KB Output is correct
46 Correct 4 ms 748 KB Output is correct
47 Correct 4 ms 748 KB Output is correct
48 Correct 4 ms 748 KB Output is correct
49 Correct 3 ms 620 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 89 ms 6764 KB Output is correct
52 Correct 89 ms 6836 KB Output is correct
53 Correct 87 ms 6764 KB Output is correct
54 Correct 89 ms 6836 KB Output is correct
55 Correct 90 ms 6764 KB Output is correct
56 Correct 88 ms 6764 KB Output is correct
57 Correct 93 ms 6820 KB Output is correct
58 Correct 55 ms 6764 KB Output is correct
59 Correct 59 ms 6764 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 116 ms 10604 KB Output is correct
62 Correct 117 ms 10656 KB Output is correct
63 Correct 115 ms 10628 KB Output is correct
64 Correct 115 ms 10604 KB Output is correct
65 Correct 115 ms 10732 KB Output is correct
66 Correct 120 ms 10604 KB Output is correct
67 Correct 116 ms 10732 KB Output is correct
68 Correct 120 ms 10604 KB Output is correct
69 Correct 92 ms 6892 KB Output is correct
70 Correct 1 ms 364 KB Output is correct