답안 #692461

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
692461 2023-02-01T13:15:40 Z saayan007 Mountains (NOI20_mountains) C++17
100 / 100
123 ms 20052 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;

#define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i)
#define fr first 
#define sc second
#define mp make_pair
#define pb push_back
#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll n;
ll lef[300000 + 1];
ll rig[300000 + 1];

ll rsum(ll pos) {
    ll s = 0;
    while(pos >= 1) {
        s += rig[pos];
        pos -= (pos & -pos);
    }
    return s;
}

void rupdate(ll pos, ll val) {
    while(pos <= n) {
        rig[pos] += val;
        pos += (pos & -pos);
    }
}

ll lsum(ll pos) {
    ll s = 0;
    while(pos >= 1) {
        s += lef[pos];
        pos -= (pos & -pos);
    }
    return s;
}

void lupdate(ll pos, ll val) {
    while(pos <= n) {
        lef[pos] += val;
        pos += (pos & -pos);
    }
}

void solve()
{
    cin >> n;
    pl h[n + 1];
    fur(i, 1, n) {
        cin >> h[i].fr;
        h[i].sc = i;
    }
    sort(h + 1, h + n + 1, [&] (pl lef, pl rig) {
        if(lef.fr != rig.fr)
            return lef.fr < rig.fr;
        return lef.sc > rig.sc;
    });
    /* fur(i, 1, n) */
    /*     cout << h[i].fr << ' ' << h[i].sc << nl; */
    /* cout << nl; */
    ll l[n + 1], r[n + 1];
    
    fur(i, 1, n) {
        l[h[i].sc] = lsum(h[i].sc);
        lupdate(h[i].sc, 1);
    }
    /* fur(i, 1, n) */
    /*     cout << l[i] << ' '; */
    /* cout << nl; */
    fur(i, 1, n)
        h[i].sc = n + 1 - h[i].sc;
    sort(h + 1, h + n + 1, [&] (pl lef, pl rig) {
        if(lef.fr != rig.fr)
            return lef.fr < rig.fr;
        return lef.sc > rig.sc;
    });
    /* fur(i, 1, n) */
    /*     cout << h[i].fr << ' ' << h[i].sc << nl; */
    /* cout << nl; */
    fur(i, 1, n) {
        r[n + 1 - h[i].sc] = rsum(h[i].sc);
        rupdate(h[i].sc, 1);
    }
    /* fur(i, 1, n) */
    /*     cout << r[i] << ' '; */
    /* cout << nl; */

    ll ans = 0;
    fur(i, 1, n) {
        ans += l[i] * r[i];
    }
    cout << ans << nl;
}

int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);

	ll t = 1;
    /* cin >> t; */
    while(t--)
    {
        solve();
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 78 ms 19844 KB Output is correct
3 Correct 80 ms 19896 KB Output is correct
4 Correct 79 ms 19848 KB Output is correct
5 Correct 78 ms 19836 KB Output is correct
6 Correct 77 ms 19916 KB Output is correct
7 Correct 81 ms 19896 KB Output is correct
8 Correct 89 ms 19900 KB Output is correct
9 Correct 83 ms 19944 KB Output is correct
10 Correct 81 ms 19972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 14932 KB Output is correct
2 Correct 86 ms 14980 KB Output is correct
3 Correct 71 ms 14948 KB Output is correct
4 Correct 81 ms 14924 KB Output is correct
5 Correct 71 ms 14924 KB Output is correct
6 Correct 85 ms 14940 KB Output is correct
7 Correct 82 ms 14924 KB Output is correct
8 Correct 86 ms 14936 KB Output is correct
9 Correct 87 ms 14940 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 14932 KB Output is correct
2 Correct 86 ms 14980 KB Output is correct
3 Correct 71 ms 14948 KB Output is correct
4 Correct 81 ms 14924 KB Output is correct
5 Correct 71 ms 14924 KB Output is correct
6 Correct 85 ms 14940 KB Output is correct
7 Correct 82 ms 14924 KB Output is correct
8 Correct 86 ms 14936 KB Output is correct
9 Correct 87 ms 14940 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 86 ms 15180 KB Output is correct
12 Correct 85 ms 15244 KB Output is correct
13 Correct 84 ms 15364 KB Output is correct
14 Correct 86 ms 15180 KB Output is correct
15 Correct 85 ms 15328 KB Output is correct
16 Correct 84 ms 15216 KB Output is correct
17 Correct 90 ms 15180 KB Output is correct
18 Correct 66 ms 15200 KB Output is correct
19 Correct 61 ms 15176 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 4 ms 980 KB Output is correct
14 Correct 4 ms 928 KB Output is correct
15 Correct 3 ms 924 KB Output is correct
16 Correct 4 ms 988 KB Output is correct
17 Correct 4 ms 980 KB Output is correct
18 Correct 4 ms 984 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 14932 KB Output is correct
2 Correct 86 ms 14980 KB Output is correct
3 Correct 71 ms 14948 KB Output is correct
4 Correct 81 ms 14924 KB Output is correct
5 Correct 71 ms 14924 KB Output is correct
6 Correct 85 ms 14940 KB Output is correct
7 Correct 82 ms 14924 KB Output is correct
8 Correct 86 ms 14936 KB Output is correct
9 Correct 87 ms 14940 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 86 ms 15180 KB Output is correct
12 Correct 85 ms 15244 KB Output is correct
13 Correct 84 ms 15364 KB Output is correct
14 Correct 86 ms 15180 KB Output is correct
15 Correct 85 ms 15328 KB Output is correct
16 Correct 84 ms 15216 KB Output is correct
17 Correct 90 ms 15180 KB Output is correct
18 Correct 66 ms 15200 KB Output is correct
19 Correct 61 ms 15176 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 98 ms 16128 KB Output is correct
22 Correct 99 ms 16132 KB Output is correct
23 Correct 103 ms 16084 KB Output is correct
24 Correct 99 ms 16124 KB Output is correct
25 Correct 103 ms 16240 KB Output is correct
26 Correct 104 ms 16076 KB Output is correct
27 Correct 98 ms 16076 KB Output is correct
28 Correct 64 ms 16076 KB Output is correct
29 Correct 56 ms 16204 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 78 ms 19844 KB Output is correct
3 Correct 80 ms 19896 KB Output is correct
4 Correct 79 ms 19848 KB Output is correct
5 Correct 78 ms 19836 KB Output is correct
6 Correct 77 ms 19916 KB Output is correct
7 Correct 81 ms 19896 KB Output is correct
8 Correct 89 ms 19900 KB Output is correct
9 Correct 83 ms 19944 KB Output is correct
10 Correct 81 ms 19972 KB Output is correct
11 Correct 71 ms 14932 KB Output is correct
12 Correct 86 ms 14980 KB Output is correct
13 Correct 71 ms 14948 KB Output is correct
14 Correct 81 ms 14924 KB Output is correct
15 Correct 71 ms 14924 KB Output is correct
16 Correct 85 ms 14940 KB Output is correct
17 Correct 82 ms 14924 KB Output is correct
18 Correct 86 ms 14936 KB Output is correct
19 Correct 87 ms 14940 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 86 ms 15180 KB Output is correct
22 Correct 85 ms 15244 KB Output is correct
23 Correct 84 ms 15364 KB Output is correct
24 Correct 86 ms 15180 KB Output is correct
25 Correct 85 ms 15328 KB Output is correct
26 Correct 84 ms 15216 KB Output is correct
27 Correct 90 ms 15180 KB Output is correct
28 Correct 66 ms 15200 KB Output is correct
29 Correct 61 ms 15176 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 0 ms 328 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 332 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 4 ms 980 KB Output is correct
42 Correct 3 ms 980 KB Output is correct
43 Correct 4 ms 980 KB Output is correct
44 Correct 4 ms 928 KB Output is correct
45 Correct 3 ms 924 KB Output is correct
46 Correct 4 ms 988 KB Output is correct
47 Correct 4 ms 980 KB Output is correct
48 Correct 4 ms 984 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 1 ms 324 KB Output is correct
51 Correct 98 ms 16128 KB Output is correct
52 Correct 99 ms 16132 KB Output is correct
53 Correct 103 ms 16084 KB Output is correct
54 Correct 99 ms 16124 KB Output is correct
55 Correct 103 ms 16240 KB Output is correct
56 Correct 104 ms 16076 KB Output is correct
57 Correct 98 ms 16076 KB Output is correct
58 Correct 64 ms 16076 KB Output is correct
59 Correct 56 ms 16204 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 123 ms 19836 KB Output is correct
62 Correct 110 ms 19848 KB Output is correct
63 Correct 119 ms 19844 KB Output is correct
64 Correct 121 ms 19980 KB Output is correct
65 Correct 122 ms 19868 KB Output is correct
66 Correct 118 ms 19840 KB Output is correct
67 Correct 117 ms 19840 KB Output is correct
68 Correct 122 ms 20052 KB Output is correct
69 Correct 96 ms 16204 KB Output is correct
70 Correct 0 ms 212 KB Output is correct