답안 #1020580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020580 2024-07-12T07:13:56 Z lamagril Mountains (NOI20_mountains) C++14
100 / 100
172 ms 29484 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N=3e5+5;
vector<int> v(N);
vector<int> f[N];

struct fenwick{
    int d[N];
    void update(int idx,int vl){
        while(idx<N){
            d[idx]+=vl;
            idx+=idx&(-idx);
        }
    }
    int query(int idx){
        int sm=0;
        while(idx>0){
            sm+=d[idx];
            idx-=(idx&-idx);
        }
        return sm;
    }
} fe;

int32_t main(){
    cin.tie(NULL)->sync_with_stdio(false);
    int ans=0;
    int n; cin >> n;
    vector<int> a;
    for(int i=1 ; i<=n ; i++){
        fe.update(i,1);
    }
    for(int i=1 ; i<=n ; i++) cin >> v[i],a.push_back(v[i]);
    sort(a.begin(),a.end()); 
    for(int i=1 ; i<=n ; i++){
        v[i]=lower_bound(a.begin(),a.end(),v[i])-a.begin()+1;
    }
    for(int i=1 ; i<=n ; i++){
        f[v[i]].push_back(i);
    }
    for(int i=n ; i>=1 ; i--){
        if(f[i].empty()) continue;
        for(int j:f[i]){
            fe.update(j,-1);
        }
        for(int j:f[i]){
            ans+=fe.query(j)*(fe.query(n)-fe.query(j));
        }
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 90 ms 29472 KB Output is correct
3 Correct 85 ms 29384 KB Output is correct
4 Correct 88 ms 29384 KB Output is correct
5 Correct 86 ms 29312 KB Output is correct
6 Correct 103 ms 29376 KB Output is correct
7 Correct 86 ms 29380 KB Output is correct
8 Correct 83 ms 29332 KB Output is correct
9 Correct 95 ms 25484 KB Output is correct
10 Correct 95 ms 25636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 20356 KB Output is correct
2 Correct 49 ms 20168 KB Output is correct
3 Correct 51 ms 19652 KB Output is correct
4 Correct 45 ms 19872 KB Output is correct
5 Correct 47 ms 20420 KB Output is correct
6 Correct 45 ms 19652 KB Output is correct
7 Correct 57 ms 19752 KB Output is correct
8 Correct 35 ms 19396 KB Output is correct
9 Correct 37 ms 19408 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 20356 KB Output is correct
2 Correct 49 ms 20168 KB Output is correct
3 Correct 51 ms 19652 KB Output is correct
4 Correct 45 ms 19872 KB Output is correct
5 Correct 47 ms 20420 KB Output is correct
6 Correct 45 ms 19652 KB Output is correct
7 Correct 57 ms 19752 KB Output is correct
8 Correct 35 ms 19396 KB Output is correct
9 Correct 37 ms 19408 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 61 ms 18624 KB Output is correct
12 Correct 67 ms 18628 KB Output is correct
13 Correct 59 ms 18624 KB Output is correct
14 Correct 57 ms 18640 KB Output is correct
15 Correct 59 ms 18680 KB Output is correct
16 Correct 58 ms 18676 KB Output is correct
17 Correct 58 ms 18860 KB Output is correct
18 Correct 35 ms 18128 KB Output is correct
19 Correct 48 ms 18120 KB Output is correct
20 Correct 3 ms 9984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Correct 3 ms 9992 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 3 ms 9824 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 9980 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Correct 3 ms 9992 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 3 ms 9824 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 9980 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 7 ms 10592 KB Output is correct
12 Correct 6 ms 10580 KB Output is correct
13 Correct 9 ms 10492 KB Output is correct
14 Correct 7 ms 10592 KB Output is correct
15 Correct 7 ms 10476 KB Output is correct
16 Correct 6 ms 10592 KB Output is correct
17 Correct 6 ms 10592 KB Output is correct
18 Correct 7 ms 10332 KB Output is correct
19 Correct 5 ms 10332 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 20356 KB Output is correct
2 Correct 49 ms 20168 KB Output is correct
3 Correct 51 ms 19652 KB Output is correct
4 Correct 45 ms 19872 KB Output is correct
5 Correct 47 ms 20420 KB Output is correct
6 Correct 45 ms 19652 KB Output is correct
7 Correct 57 ms 19752 KB Output is correct
8 Correct 35 ms 19396 KB Output is correct
9 Correct 37 ms 19408 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 61 ms 18624 KB Output is correct
12 Correct 67 ms 18628 KB Output is correct
13 Correct 59 ms 18624 KB Output is correct
14 Correct 57 ms 18640 KB Output is correct
15 Correct 59 ms 18680 KB Output is correct
16 Correct 58 ms 18676 KB Output is correct
17 Correct 58 ms 18860 KB Output is correct
18 Correct 35 ms 18128 KB Output is correct
19 Correct 48 ms 18120 KB Output is correct
20 Correct 3 ms 9984 KB Output is correct
21 Correct 145 ms 21184 KB Output is correct
22 Correct 120 ms 21184 KB Output is correct
23 Correct 122 ms 21188 KB Output is correct
24 Correct 121 ms 21184 KB Output is correct
25 Correct 119 ms 21040 KB Output is correct
26 Correct 141 ms 21112 KB Output is correct
27 Correct 121 ms 21188 KB Output is correct
28 Correct 64 ms 20680 KB Output is correct
29 Correct 56 ms 20736 KB Output is correct
30 Correct 3 ms 9816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 90 ms 29472 KB Output is correct
3 Correct 85 ms 29384 KB Output is correct
4 Correct 88 ms 29384 KB Output is correct
5 Correct 86 ms 29312 KB Output is correct
6 Correct 103 ms 29376 KB Output is correct
7 Correct 86 ms 29380 KB Output is correct
8 Correct 83 ms 29332 KB Output is correct
9 Correct 95 ms 25484 KB Output is correct
10 Correct 95 ms 25636 KB Output is correct
11 Correct 47 ms 20356 KB Output is correct
12 Correct 49 ms 20168 KB Output is correct
13 Correct 51 ms 19652 KB Output is correct
14 Correct 45 ms 19872 KB Output is correct
15 Correct 47 ms 20420 KB Output is correct
16 Correct 45 ms 19652 KB Output is correct
17 Correct 57 ms 19752 KB Output is correct
18 Correct 35 ms 19396 KB Output is correct
19 Correct 37 ms 19408 KB Output is correct
20 Correct 3 ms 9820 KB Output is correct
21 Correct 61 ms 18624 KB Output is correct
22 Correct 67 ms 18628 KB Output is correct
23 Correct 59 ms 18624 KB Output is correct
24 Correct 57 ms 18640 KB Output is correct
25 Correct 59 ms 18680 KB Output is correct
26 Correct 58 ms 18676 KB Output is correct
27 Correct 58 ms 18860 KB Output is correct
28 Correct 35 ms 18128 KB Output is correct
29 Correct 48 ms 18120 KB Output is correct
30 Correct 3 ms 9984 KB Output is correct
31 Correct 3 ms 9820 KB Output is correct
32 Correct 3 ms 9992 KB Output is correct
33 Correct 3 ms 9820 KB Output is correct
34 Correct 3 ms 9820 KB Output is correct
35 Correct 3 ms 9824 KB Output is correct
36 Correct 3 ms 9820 KB Output is correct
37 Correct 3 ms 9820 KB Output is correct
38 Correct 3 ms 9820 KB Output is correct
39 Correct 3 ms 9980 KB Output is correct
40 Correct 3 ms 9820 KB Output is correct
41 Correct 7 ms 10592 KB Output is correct
42 Correct 6 ms 10580 KB Output is correct
43 Correct 9 ms 10492 KB Output is correct
44 Correct 7 ms 10592 KB Output is correct
45 Correct 7 ms 10476 KB Output is correct
46 Correct 6 ms 10592 KB Output is correct
47 Correct 6 ms 10592 KB Output is correct
48 Correct 7 ms 10332 KB Output is correct
49 Correct 5 ms 10332 KB Output is correct
50 Correct 4 ms 9820 KB Output is correct
51 Correct 145 ms 21184 KB Output is correct
52 Correct 120 ms 21184 KB Output is correct
53 Correct 122 ms 21188 KB Output is correct
54 Correct 121 ms 21184 KB Output is correct
55 Correct 119 ms 21040 KB Output is correct
56 Correct 141 ms 21112 KB Output is correct
57 Correct 121 ms 21188 KB Output is correct
58 Correct 64 ms 20680 KB Output is correct
59 Correct 56 ms 20736 KB Output is correct
60 Correct 3 ms 9816 KB Output is correct
61 Correct 156 ms 29376 KB Output is correct
62 Correct 172 ms 29384 KB Output is correct
63 Correct 143 ms 29484 KB Output is correct
64 Correct 148 ms 29292 KB Output is correct
65 Correct 148 ms 29376 KB Output is correct
66 Correct 140 ms 29448 KB Output is correct
67 Correct 154 ms 29376 KB Output is correct
68 Correct 137 ms 25536 KB Output is correct
69 Correct 127 ms 21440 KB Output is correct
70 Correct 3 ms 9820 KB Output is correct