답안 #570216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570216 2022-05-28T20:42:30 Z thatsgonzalez Mountains (NOI20_mountains) C++14
100 / 100
125 ms 12116 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef pair <ll,ll> pl;
typedef vector<pl> vpl;

#define s second
#define f first

int n;

struct FT
{
    int n; vl dp;
    FT (int n){
        this->n = n;
        dp.assign(n+1,0);
    }

    int lsb(int x){
        return x & (-x);
    }

    ll query(int ind){
        ll res=0;
        while(ind){
            res+=dp[ind];
            ind-=lsb(ind);
        }
        return res;
    }
    
    void add(int ind, ll value){
        while(ind<=n){
            dp[ind]+=value;
            ind+=lsb(ind);
        }
    }
};

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    FT ft1(n),ft2(n);
    ll a[n]; 
    vpl aux(n);
    for(int i=0; i<n; i++){
      ll x; cin>>x; aux[i]={x,i};
    }
    sort(aux.begin(),aux.end()); a[aux[0].s]=1; int temp=1;
    for(int i=1; i<n; i++){
      if(aux[i].f==aux[i-1].f) a[aux[i].s]=temp;
      else temp++, a[aux[i].s]=temp;
    }
    //for(auto &x: a) cout<<x<<" "; cout<<endl; 
    ll mx=0;
    for(int i=n-1; i>=0; i--){
      mx=max(mx,a[i]);
      ft1.add(a[i],1);
    }
    //cout<<query(mx-1,1)<<endl;
    //int top=n+99;
    ll ans=0;
    for(int i=0; i<n; i++){
      ft1.add(a[i],-1LL);
      //cout<<query(a[i]-1,0)<<" "<<query(a[i]-1,1)<<endl;
      ans+=(ll)(ft1.query(a[i]-1)*(ft2.query(a[i]-1)));
      ft2.add(a[i],1LL);
    }
    cout<<ans<<endl;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 224 KB Output is correct
2 Correct 92 ms 11988 KB Output is correct
3 Correct 90 ms 11988 KB Output is correct
4 Correct 94 ms 12056 KB Output is correct
5 Correct 90 ms 12048 KB Output is correct
6 Correct 89 ms 12048 KB Output is correct
7 Correct 105 ms 12056 KB Output is correct
8 Correct 90 ms 11988 KB Output is correct
9 Correct 100 ms 11988 KB Output is correct
10 Correct 102 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 12048 KB Output is correct
2 Correct 123 ms 12052 KB Output is correct
3 Correct 123 ms 12056 KB Output is correct
4 Correct 112 ms 11988 KB Output is correct
5 Correct 121 ms 12052 KB Output is correct
6 Correct 117 ms 12056 KB Output is correct
7 Correct 113 ms 11988 KB Output is correct
8 Correct 103 ms 12060 KB Output is correct
9 Correct 105 ms 11988 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 12048 KB Output is correct
2 Correct 123 ms 12052 KB Output is correct
3 Correct 123 ms 12056 KB Output is correct
4 Correct 112 ms 11988 KB Output is correct
5 Correct 121 ms 12052 KB Output is correct
6 Correct 117 ms 12056 KB Output is correct
7 Correct 113 ms 11988 KB Output is correct
8 Correct 103 ms 12060 KB Output is correct
9 Correct 105 ms 11988 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 112 ms 11988 KB Output is correct
12 Correct 108 ms 11988 KB Output is correct
13 Correct 107 ms 12048 KB Output is correct
14 Correct 109 ms 12052 KB Output is correct
15 Correct 112 ms 12048 KB Output is correct
16 Correct 103 ms 12048 KB Output is correct
17 Correct 107 ms 12052 KB Output is correct
18 Correct 87 ms 11988 KB Output is correct
19 Correct 90 ms 11988 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 12048 KB Output is correct
2 Correct 123 ms 12052 KB Output is correct
3 Correct 123 ms 12056 KB Output is correct
4 Correct 112 ms 11988 KB Output is correct
5 Correct 121 ms 12052 KB Output is correct
6 Correct 117 ms 12056 KB Output is correct
7 Correct 113 ms 11988 KB Output is correct
8 Correct 103 ms 12060 KB Output is correct
9 Correct 105 ms 11988 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 112 ms 11988 KB Output is correct
12 Correct 108 ms 11988 KB Output is correct
13 Correct 107 ms 12048 KB Output is correct
14 Correct 109 ms 12052 KB Output is correct
15 Correct 112 ms 12048 KB Output is correct
16 Correct 103 ms 12048 KB Output is correct
17 Correct 107 ms 12052 KB Output is correct
18 Correct 87 ms 11988 KB Output is correct
19 Correct 90 ms 11988 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 100 ms 11988 KB Output is correct
22 Correct 99 ms 12052 KB Output is correct
23 Correct 97 ms 12052 KB Output is correct
24 Correct 99 ms 12052 KB Output is correct
25 Correct 92 ms 12060 KB Output is correct
26 Correct 96 ms 12044 KB Output is correct
27 Correct 101 ms 11988 KB Output is correct
28 Correct 75 ms 12108 KB Output is correct
29 Correct 75 ms 11988 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 224 KB Output is correct
2 Correct 92 ms 11988 KB Output is correct
3 Correct 90 ms 11988 KB Output is correct
4 Correct 94 ms 12056 KB Output is correct
5 Correct 90 ms 12048 KB Output is correct
6 Correct 89 ms 12048 KB Output is correct
7 Correct 105 ms 12056 KB Output is correct
8 Correct 90 ms 11988 KB Output is correct
9 Correct 100 ms 11988 KB Output is correct
10 Correct 102 ms 12116 KB Output is correct
11 Correct 119 ms 12048 KB Output is correct
12 Correct 123 ms 12052 KB Output is correct
13 Correct 123 ms 12056 KB Output is correct
14 Correct 112 ms 11988 KB Output is correct
15 Correct 121 ms 12052 KB Output is correct
16 Correct 117 ms 12056 KB Output is correct
17 Correct 113 ms 11988 KB Output is correct
18 Correct 103 ms 12060 KB Output is correct
19 Correct 105 ms 11988 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 112 ms 11988 KB Output is correct
22 Correct 108 ms 11988 KB Output is correct
23 Correct 107 ms 12048 KB Output is correct
24 Correct 109 ms 12052 KB Output is correct
25 Correct 112 ms 12048 KB Output is correct
26 Correct 103 ms 12048 KB Output is correct
27 Correct 107 ms 12052 KB Output is correct
28 Correct 87 ms 11988 KB Output is correct
29 Correct 90 ms 11988 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 4 ms 724 KB Output is correct
43 Correct 4 ms 596 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 4 ms 724 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 100 ms 11988 KB Output is correct
52 Correct 99 ms 12052 KB Output is correct
53 Correct 97 ms 12052 KB Output is correct
54 Correct 99 ms 12052 KB Output is correct
55 Correct 92 ms 12060 KB Output is correct
56 Correct 96 ms 12044 KB Output is correct
57 Correct 101 ms 11988 KB Output is correct
58 Correct 75 ms 12108 KB Output is correct
59 Correct 75 ms 11988 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 125 ms 12044 KB Output is correct
62 Correct 120 ms 12048 KB Output is correct
63 Correct 118 ms 12048 KB Output is correct
64 Correct 117 ms 12044 KB Output is correct
65 Correct 113 ms 12060 KB Output is correct
66 Correct 114 ms 11988 KB Output is correct
67 Correct 109 ms 11988 KB Output is correct
68 Correct 119 ms 12044 KB Output is correct
69 Correct 95 ms 11988 KB Output is correct
70 Correct 0 ms 212 KB Output is correct