Submission #337511

#TimeUsernameProblemLanguageResultExecution timeMemory
337511ncduy0303Mountains (NOI20_mountains)C++17
100 / 100
878 ms32000 KiB
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class K, class V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n; cin >> n;
    vector<ll> a(n);
    for (ll &x : a) cin >> x;
    vector<ll> lb(n), rb(n);
    ordered_set<ar<ll,2>> os;
    for (int i = 0; i < n; i++) {
        lb[i] = os.order_of_key({a[i], 0});
        os.insert({a[i], i});
    }
    os.clear();
    for (int i = n - 1; i >= 0; i--) {
        rb[i] = os.order_of_key({a[i], 0});
        os.insert({a[i], i});
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) ans += lb[i] * rb[i];
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}
#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...