Submission #349380

#TimeUsernameProblemLanguageResultExecution timeMemory
349380phathnvMountains (NOI20_mountains)C++11
100 / 100
120 ms10732 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 3e5 + 1; struct FenwickTree{ int d[N]; void update(int x){ for(; x < N; x += x & -x) d[x]++; } int get(int x){ int res = 0; for(; x > 0; x -= x & -x) res += d[x]; return res; } int getRange(int l, int r){ assert(l <= r); return get(r) - get(l - 1); } } bit; int n, ind[N]; ll a[N]; void ReadInput(){ cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; } void Solve(){ for(int i = 1; i <= n; i++) ind[i] = i; sort(ind + 1, ind + 1 + n, [&](const int &x, const int &y){ return a[x] < a[y]; }); ll res = 0; for(int i = 1; i <= n; i++){ int j = i; while (j < n && a[ind[i]] == a[ind[j + 1]]) j++; for(int k = i; k <= j; k++) res += (ll) bit.getRange(1, ind[k]) * bit.getRange(ind[k], n); for(int k = i; k <= j; k++) bit.update(ind[k]); i = j; } cout << res; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ReadInput(); Solve(); return 0; }
#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...