Submission #626181

# Submission time Handle Problem Language Result Execution time Memory
626181 2022-08-11T09:31:54 Z PoonYaPat Mountains (NOI20_mountains) C++14
100 / 100
145 ms 15408 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;

int n,fen[300001],h[300001];
vector<pii> v;
ll ans,a[300001];

ll find(int x) {
    ll cnt=0;
    while (x) {
        cnt+=fen[x];
        x-=(x&-x);
    }
    return cnt;
}

void update(int x) {
    while (x<=n) {
        ++fen[x];
        x+=(x&-x);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1; i<=n; ++i) {
        ll x; cin>>x;
        v.push_back(pii(x,i));
    }
    sort(v.begin(),v.end());
    int cnt=1;
    ll pre=-1;
    for (auto s : v) {
        if (s.first!=pre) {
            pre=s.first;
            h[s.second]=cnt++;
        } else h[s.second]=cnt-1;
    }

    for (int i=1; i<=n; ++i) {
        a[i]=find(h[i]-1);
        update(h[i]);
    }
    memset(fen,0,sizeof(fen));
    for (int i=n; i>=1;--i) {
        ans+=(a[i]*find(h[i]-1));
        update(h[i]);
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 82 ms 15296 KB Output is correct
3 Correct 84 ms 15280 KB Output is correct
4 Correct 93 ms 15372 KB Output is correct
5 Correct 83 ms 15400 KB Output is correct
6 Correct 83 ms 15404 KB Output is correct
7 Correct 79 ms 15360 KB Output is correct
8 Correct 95 ms 15348 KB Output is correct
9 Correct 83 ms 15368 KB Output is correct
10 Correct 81 ms 15408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 10332 KB Output is correct
2 Correct 75 ms 10364 KB Output is correct
3 Correct 92 ms 10368 KB Output is correct
4 Correct 65 ms 10340 KB Output is correct
5 Correct 68 ms 10360 KB Output is correct
6 Correct 70 ms 10380 KB Output is correct
7 Correct 78 ms 10436 KB Output is correct
8 Correct 66 ms 10376 KB Output is correct
9 Correct 54 ms 10364 KB Output is correct
10 Correct 1 ms 1476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 10332 KB Output is correct
2 Correct 75 ms 10364 KB Output is correct
3 Correct 92 ms 10368 KB Output is correct
4 Correct 65 ms 10340 KB Output is correct
5 Correct 68 ms 10360 KB Output is correct
6 Correct 70 ms 10380 KB Output is correct
7 Correct 78 ms 10436 KB Output is correct
8 Correct 66 ms 10376 KB Output is correct
9 Correct 54 ms 10364 KB Output is correct
10 Correct 1 ms 1476 KB Output is correct
11 Correct 72 ms 10668 KB Output is correct
12 Correct 82 ms 10668 KB Output is correct
13 Correct 74 ms 10620 KB Output is correct
14 Correct 79 ms 10792 KB Output is correct
15 Correct 81 ms 10668 KB Output is correct
16 Correct 78 ms 10668 KB Output is correct
17 Correct 85 ms 10612 KB Output is correct
18 Correct 56 ms 10720 KB Output is correct
19 Correct 55 ms 10680 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 2 ms 1492 KB Output is correct
5 Correct 2 ms 1492 KB Output is correct
6 Correct 1 ms 1500 KB Output is correct
7 Correct 2 ms 1500 KB Output is correct
8 Correct 1 ms 1496 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 2 ms 1492 KB Output is correct
5 Correct 2 ms 1492 KB Output is correct
6 Correct 1 ms 1500 KB Output is correct
7 Correct 2 ms 1500 KB Output is correct
8 Correct 1 ms 1496 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1488 KB Output is correct
11 Correct 9 ms 2008 KB Output is correct
12 Correct 4 ms 2008 KB Output is correct
13 Correct 6 ms 2024 KB Output is correct
14 Correct 5 ms 2008 KB Output is correct
15 Correct 5 ms 2008 KB Output is correct
16 Correct 5 ms 2008 KB Output is correct
17 Correct 6 ms 2008 KB Output is correct
18 Correct 6 ms 2012 KB Output is correct
19 Correct 3 ms 1892 KB Output is correct
20 Correct 2 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 10332 KB Output is correct
2 Correct 75 ms 10364 KB Output is correct
3 Correct 92 ms 10368 KB Output is correct
4 Correct 65 ms 10340 KB Output is correct
5 Correct 68 ms 10360 KB Output is correct
6 Correct 70 ms 10380 KB Output is correct
7 Correct 78 ms 10436 KB Output is correct
8 Correct 66 ms 10376 KB Output is correct
9 Correct 54 ms 10364 KB Output is correct
10 Correct 1 ms 1476 KB Output is correct
11 Correct 72 ms 10668 KB Output is correct
12 Correct 82 ms 10668 KB Output is correct
13 Correct 74 ms 10620 KB Output is correct
14 Correct 79 ms 10792 KB Output is correct
15 Correct 81 ms 10668 KB Output is correct
16 Correct 78 ms 10668 KB Output is correct
17 Correct 85 ms 10612 KB Output is correct
18 Correct 56 ms 10720 KB Output is correct
19 Correct 55 ms 10680 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
21 Correct 81 ms 11508 KB Output is correct
22 Correct 116 ms 11500 KB Output is correct
23 Correct 81 ms 11528 KB Output is correct
24 Correct 80 ms 11540 KB Output is correct
25 Correct 99 ms 11504 KB Output is correct
26 Correct 84 ms 11552 KB Output is correct
27 Correct 82 ms 11504 KB Output is correct
28 Correct 59 ms 11488 KB Output is correct
29 Correct 79 ms 11536 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 82 ms 15296 KB Output is correct
3 Correct 84 ms 15280 KB Output is correct
4 Correct 93 ms 15372 KB Output is correct
5 Correct 83 ms 15400 KB Output is correct
6 Correct 83 ms 15404 KB Output is correct
7 Correct 79 ms 15360 KB Output is correct
8 Correct 95 ms 15348 KB Output is correct
9 Correct 83 ms 15368 KB Output is correct
10 Correct 81 ms 15408 KB Output is correct
11 Correct 91 ms 10332 KB Output is correct
12 Correct 75 ms 10364 KB Output is correct
13 Correct 92 ms 10368 KB Output is correct
14 Correct 65 ms 10340 KB Output is correct
15 Correct 68 ms 10360 KB Output is correct
16 Correct 70 ms 10380 KB Output is correct
17 Correct 78 ms 10436 KB Output is correct
18 Correct 66 ms 10376 KB Output is correct
19 Correct 54 ms 10364 KB Output is correct
20 Correct 1 ms 1476 KB Output is correct
21 Correct 72 ms 10668 KB Output is correct
22 Correct 82 ms 10668 KB Output is correct
23 Correct 74 ms 10620 KB Output is correct
24 Correct 79 ms 10792 KB Output is correct
25 Correct 81 ms 10668 KB Output is correct
26 Correct 78 ms 10668 KB Output is correct
27 Correct 85 ms 10612 KB Output is correct
28 Correct 56 ms 10720 KB Output is correct
29 Correct 55 ms 10680 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
31 Correct 1 ms 1492 KB Output is correct
32 Correct 1 ms 1492 KB Output is correct
33 Correct 2 ms 1492 KB Output is correct
34 Correct 2 ms 1492 KB Output is correct
35 Correct 2 ms 1492 KB Output is correct
36 Correct 1 ms 1500 KB Output is correct
37 Correct 2 ms 1500 KB Output is correct
38 Correct 1 ms 1496 KB Output is correct
39 Correct 1 ms 1492 KB Output is correct
40 Correct 1 ms 1488 KB Output is correct
41 Correct 9 ms 2008 KB Output is correct
42 Correct 4 ms 2008 KB Output is correct
43 Correct 6 ms 2024 KB Output is correct
44 Correct 5 ms 2008 KB Output is correct
45 Correct 5 ms 2008 KB Output is correct
46 Correct 5 ms 2008 KB Output is correct
47 Correct 6 ms 2008 KB Output is correct
48 Correct 6 ms 2012 KB Output is correct
49 Correct 3 ms 1892 KB Output is correct
50 Correct 2 ms 1492 KB Output is correct
51 Correct 81 ms 11508 KB Output is correct
52 Correct 116 ms 11500 KB Output is correct
53 Correct 81 ms 11528 KB Output is correct
54 Correct 80 ms 11540 KB Output is correct
55 Correct 99 ms 11504 KB Output is correct
56 Correct 84 ms 11552 KB Output is correct
57 Correct 82 ms 11504 KB Output is correct
58 Correct 59 ms 11488 KB Output is correct
59 Correct 79 ms 11536 KB Output is correct
60 Correct 1 ms 1492 KB Output is correct
61 Correct 112 ms 15320 KB Output is correct
62 Correct 120 ms 15300 KB Output is correct
63 Correct 145 ms 15320 KB Output is correct
64 Correct 119 ms 15328 KB Output is correct
65 Correct 111 ms 15316 KB Output is correct
66 Correct 133 ms 15356 KB Output is correct
67 Correct 110 ms 15328 KB Output is correct
68 Correct 109 ms 15408 KB Output is correct
69 Correct 89 ms 11580 KB Output is correct
70 Correct 1 ms 1488 KB Output is correct