Submission #1328241

#TimeUsernameProblemLanguageResultExecution timeMemory
1328241michael12Mountains (NOI20_mountains)C++20
0 / 100
229 ms2828 KiB
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define int long long
using namespace std;
const int maxn = 5e5 + 5;
const int oo = 1e18;
int tree[4 * maxn][3];
void update(int node, int start, int end, int id, int val, int P){
    if(start == end){
        tree[node][P] = val;
    }
    else{
        int mid = (start + end) / 2;
        if(mid >= id){
            update(2 * node, start, mid, id, val, P);
        }
        else{
            update(2 * node + 1, mid + 1, end, id, val, P);
        }
        tree[node][P] = tree[2 * node][P] + tree[2 * node + 1][P];
    }
}
int query(int node, int start, int end, int l, int r, int id){
    if(start > r || end < l) return 0;
    if(start >= l && end <= r) return tree[node][id];
    int mid = (start + end) / 2;
    int l1 = query(2 * node, start, mid, l, r, id);
    int r1 = query(2 * node + 1, mid + 1, end, l, r, id);
    return l1 + r1;
}
int fi(int node, int start, int end, int id, int P){
    if(start == end){
        return tree[node][P];
    }
    else{
        int mid = (start + end) / 2;
        if(mid >= id){
            return fi(2 * node, start, mid, id, P);
        }
        else{
            return fi(2 * node + 1, mid + 1, end, id, P);
        }
    }
}
signed main(){
   int n;
   cin >> n;
   vector<int> a(n);
   for(int i = 0; i < n; i++){
    cin >> a[i];
   }
   int ans = 0;
   for(int i = 0; i < n; i++){
     update(1, 0, maxn, a[i], 1, 0);
   }
   // for(int i = 1; i < n; i++){
   //  cout << query(1, 0, n - 1, 0, i - 1, 0) << " ";
   // }
   // return 0;
   // for(int i = 0; i < 100; i++){
   //  cout << fi(1, 0, maxn - 1, i, 0) << " ";
   // }
   // return 0;
   for(int i = 1; i < n; i++){
     int b = query(1, 0, maxn - 1, 0, a[i] - 1, 0);
     update(1, 0, maxn - 1, a[i], b, 1);
   }
   // for(int i = 0; i < 100; i++){
   //  cout << fi(1, 0, maxn - 1, i, 1) << " ";
   // }
   // return 0;

   int cur = 0;
   for(int i = 2; i < n; i++){
      int c = query(1, 0, maxn - 1, 1, a[i] - 1, 1);
      cur += c;
   }
   cout << cur << endl;
   // int cur = 0;
   // for(int i = 2; i < n; i++){
   //   int c = query(1, 0, n - 1, 1, i - 1, 1);
   //   cur += c;
   // }
   // cout << cur;
    // mp[a[0]] = 1;
    // for(int i = 0; i < n - 1; i++){
    //    if(a[i + 1] < a[i]){
    //         if(!mp[a[i + 1] - 1] || !mp[a[i + 1]]){
    //             cur += 1;
    //         }
    //    }
    //    else{
    //        if(!mp[a[i + 1] - 1]){
    //         cur += 1;
    //        }
    //    }
    //    mp[a[i + 1]] = 1;
    // }
    // cout << cur << endl;

    
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...