답안 #209766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209766 2020-03-15T14:00:48 Z Alexa2001 Mountains (NOI20_mountains) C++17
100 / 100
140 ms 8728 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int Nmax = 3e5 + 5;

ll ans[Nmax], h[Nmax];
int a[Nmax];
int n;

class AIB
{
    int ub(int x)
    {
        return (x&(-x));
    }
    int a[Nmax];

public:
    void update(int x)
    {
        for(; x<=n; x+=ub(x)) a[x]++;
    }
    int query(int x)
    {
        int ans = 0;
        for(; x; x-=ub(x)) ans += a[x];
        return ans;
    }
    void clear()
    {
        memset(a, 0, sizeof(a));
    }
} aib;

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> n;

    int i;
    vector<int> ord;

    for(i=1; i<=n; ++i)
    {
        cin >> h[i];
        ord.push_back(i);
    }

    sort(ord.begin(), ord.end(), [](int x, int y) { return h[x] < h[y]; });

    int nr = 0;
    for(i=0; i<n; ++i)
    {
        if(!i || h[ord[i]] != h[ord[i-1]]) ++nr;
        a[ord[i]] = nr;
    }

    for(i=1; i<=n; ++i)
    {
        ans[i] = aib.query(a[i]-1);
        aib.update(a[i]);
    }

    aib.clear();
    for(i=n; i; --i)
    {
        ans[i] *= aib.query(a[i]-1);
        aib.update(a[i]);
    }

    ll sum = 0;
    for(i=1; i<=n; ++i) sum += ans[i];
    cout << sum << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 100 ms 8680 KB Output is correct
3 Correct 106 ms 8680 KB Output is correct
4 Correct 116 ms 8680 KB Output is correct
5 Correct 103 ms 8680 KB Output is correct
6 Correct 99 ms 8680 KB Output is correct
7 Correct 102 ms 8680 KB Output is correct
8 Correct 98 ms 8676 KB Output is correct
9 Correct 104 ms 8672 KB Output is correct
10 Correct 103 ms 8684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 8676 KB Output is correct
2 Correct 60 ms 8680 KB Output is correct
3 Correct 61 ms 8680 KB Output is correct
4 Correct 61 ms 8684 KB Output is correct
5 Correct 65 ms 8684 KB Output is correct
6 Correct 59 ms 8680 KB Output is correct
7 Correct 61 ms 8680 KB Output is correct
8 Correct 59 ms 8680 KB Output is correct
9 Correct 57 ms 8680 KB Output is correct
10 Correct 5 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 8676 KB Output is correct
2 Correct 60 ms 8680 KB Output is correct
3 Correct 61 ms 8680 KB Output is correct
4 Correct 61 ms 8684 KB Output is correct
5 Correct 65 ms 8684 KB Output is correct
6 Correct 59 ms 8680 KB Output is correct
7 Correct 61 ms 8680 KB Output is correct
8 Correct 59 ms 8680 KB Output is correct
9 Correct 57 ms 8680 KB Output is correct
10 Correct 5 ms 1528 KB Output is correct
11 Correct 78 ms 8680 KB Output is correct
12 Correct 74 ms 8684 KB Output is correct
13 Correct 72 ms 8680 KB Output is correct
14 Correct 71 ms 8680 KB Output is correct
15 Correct 75 ms 8680 KB Output is correct
16 Correct 74 ms 8680 KB Output is correct
17 Correct 73 ms 8680 KB Output is correct
18 Correct 61 ms 8680 KB Output is correct
19 Correct 56 ms 8680 KB Output is correct
20 Correct 5 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1532 KB Output is correct
2 Correct 5 ms 1528 KB Output is correct
3 Correct 5 ms 1528 KB Output is correct
4 Correct 6 ms 1528 KB Output is correct
5 Correct 5 ms 1528 KB Output is correct
6 Correct 6 ms 1528 KB Output is correct
7 Correct 5 ms 1528 KB Output is correct
8 Correct 5 ms 1528 KB Output is correct
9 Correct 6 ms 1528 KB Output is correct
10 Correct 6 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1532 KB Output is correct
2 Correct 5 ms 1528 KB Output is correct
3 Correct 5 ms 1528 KB Output is correct
4 Correct 6 ms 1528 KB Output is correct
5 Correct 5 ms 1528 KB Output is correct
6 Correct 6 ms 1528 KB Output is correct
7 Correct 5 ms 1528 KB Output is correct
8 Correct 5 ms 1528 KB Output is correct
9 Correct 6 ms 1528 KB Output is correct
10 Correct 6 ms 1528 KB Output is correct
11 Correct 10 ms 1912 KB Output is correct
12 Correct 9 ms 1912 KB Output is correct
13 Correct 9 ms 1784 KB Output is correct
14 Correct 9 ms 1784 KB Output is correct
15 Correct 9 ms 1784 KB Output is correct
16 Correct 9 ms 1784 KB Output is correct
17 Correct 9 ms 1784 KB Output is correct
18 Correct 9 ms 1784 KB Output is correct
19 Correct 8 ms 1784 KB Output is correct
20 Correct 5 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 8676 KB Output is correct
2 Correct 60 ms 8680 KB Output is correct
3 Correct 61 ms 8680 KB Output is correct
4 Correct 61 ms 8684 KB Output is correct
5 Correct 65 ms 8684 KB Output is correct
6 Correct 59 ms 8680 KB Output is correct
7 Correct 61 ms 8680 KB Output is correct
8 Correct 59 ms 8680 KB Output is correct
9 Correct 57 ms 8680 KB Output is correct
10 Correct 5 ms 1528 KB Output is correct
11 Correct 78 ms 8680 KB Output is correct
12 Correct 74 ms 8684 KB Output is correct
13 Correct 72 ms 8680 KB Output is correct
14 Correct 71 ms 8680 KB Output is correct
15 Correct 75 ms 8680 KB Output is correct
16 Correct 74 ms 8680 KB Output is correct
17 Correct 73 ms 8680 KB Output is correct
18 Correct 61 ms 8680 KB Output is correct
19 Correct 56 ms 8680 KB Output is correct
20 Correct 5 ms 1528 KB Output is correct
21 Correct 106 ms 8680 KB Output is correct
22 Correct 101 ms 8676 KB Output is correct
23 Correct 101 ms 8680 KB Output is correct
24 Correct 100 ms 8680 KB Output is correct
25 Correct 103 ms 8680 KB Output is correct
26 Correct 104 ms 8728 KB Output is correct
27 Correct 105 ms 8680 KB Output is correct
28 Correct 70 ms 8680 KB Output is correct
29 Correct 74 ms 8680 KB Output is correct
30 Correct 5 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 100 ms 8680 KB Output is correct
3 Correct 106 ms 8680 KB Output is correct
4 Correct 116 ms 8680 KB Output is correct
5 Correct 103 ms 8680 KB Output is correct
6 Correct 99 ms 8680 KB Output is correct
7 Correct 102 ms 8680 KB Output is correct
8 Correct 98 ms 8676 KB Output is correct
9 Correct 104 ms 8672 KB Output is correct
10 Correct 103 ms 8684 KB Output is correct
11 Correct 63 ms 8676 KB Output is correct
12 Correct 60 ms 8680 KB Output is correct
13 Correct 61 ms 8680 KB Output is correct
14 Correct 61 ms 8684 KB Output is correct
15 Correct 65 ms 8684 KB Output is correct
16 Correct 59 ms 8680 KB Output is correct
17 Correct 61 ms 8680 KB Output is correct
18 Correct 59 ms 8680 KB Output is correct
19 Correct 57 ms 8680 KB Output is correct
20 Correct 5 ms 1528 KB Output is correct
21 Correct 78 ms 8680 KB Output is correct
22 Correct 74 ms 8684 KB Output is correct
23 Correct 72 ms 8680 KB Output is correct
24 Correct 71 ms 8680 KB Output is correct
25 Correct 75 ms 8680 KB Output is correct
26 Correct 74 ms 8680 KB Output is correct
27 Correct 73 ms 8680 KB Output is correct
28 Correct 61 ms 8680 KB Output is correct
29 Correct 56 ms 8680 KB Output is correct
30 Correct 5 ms 1528 KB Output is correct
31 Correct 6 ms 1532 KB Output is correct
32 Correct 5 ms 1528 KB Output is correct
33 Correct 5 ms 1528 KB Output is correct
34 Correct 6 ms 1528 KB Output is correct
35 Correct 5 ms 1528 KB Output is correct
36 Correct 6 ms 1528 KB Output is correct
37 Correct 5 ms 1528 KB Output is correct
38 Correct 5 ms 1528 KB Output is correct
39 Correct 6 ms 1528 KB Output is correct
40 Correct 6 ms 1528 KB Output is correct
41 Correct 10 ms 1912 KB Output is correct
42 Correct 9 ms 1912 KB Output is correct
43 Correct 9 ms 1784 KB Output is correct
44 Correct 9 ms 1784 KB Output is correct
45 Correct 9 ms 1784 KB Output is correct
46 Correct 9 ms 1784 KB Output is correct
47 Correct 9 ms 1784 KB Output is correct
48 Correct 9 ms 1784 KB Output is correct
49 Correct 8 ms 1784 KB Output is correct
50 Correct 5 ms 1528 KB Output is correct
51 Correct 106 ms 8680 KB Output is correct
52 Correct 101 ms 8676 KB Output is correct
53 Correct 101 ms 8680 KB Output is correct
54 Correct 100 ms 8680 KB Output is correct
55 Correct 103 ms 8680 KB Output is correct
56 Correct 104 ms 8728 KB Output is correct
57 Correct 105 ms 8680 KB Output is correct
58 Correct 70 ms 8680 KB Output is correct
59 Correct 74 ms 8680 KB Output is correct
60 Correct 5 ms 1528 KB Output is correct
61 Correct 139 ms 8712 KB Output is correct
62 Correct 135 ms 8680 KB Output is correct
63 Correct 140 ms 8680 KB Output is correct
64 Correct 138 ms 8684 KB Output is correct
65 Correct 134 ms 8680 KB Output is correct
66 Correct 135 ms 8680 KB Output is correct
67 Correct 140 ms 8680 KB Output is correct
68 Correct 140 ms 8680 KB Output is correct
69 Correct 105 ms 8552 KB Output is correct
70 Correct 5 ms 1528 KB Output is correct