Submission #1087902

#TimeUsernameProblemLanguageResultExecution timeMemory
1087902vuavisaoMountains (NOI20_mountains)C++14
100 / 100
121 ms7064 KiB
#include <bits/stdc++.h> using namespace std; const int N = (int) 3e5 + 10; int n; long long a[N]; int L[N], R[N]; int tree[N]; void Update(int idx, int val) { for( ; idx <= n; idx += (idx & - idx)) tree[idx] += val; } int Query(int idx) { int res = 0; for( ; idx > 0; idx -= (idx & - idx)) res += tree[idx]; return res; } void compress() { vector<long long> Pos = {}; for (int i = 1; i <= n; ++ i) { Pos.push_back(a[i]); } sort(Pos.begin(), Pos.end()); Pos.resize(unique(Pos.begin(), Pos.end()) - Pos.begin()); for (int i = 1; i <= n; ++ i) { a[i] = lower_bound(Pos.begin(), Pos.end(), a[i]) - Pos.begin() + 1; } } void calc(int cnt[]) { for (int i = 0; i <= n; ++ i) tree[i] = 0; for (int i = 1; i <= n; ++ i) { cnt[i] = Query(a[i]); Update(a[i] + 1, 1); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; for (int i = 1; i <= n; ++ i) cin >> a[i]; compress(); calc(L); reverse(a + 1, a + 1 + n); calc(R); long long res = 0; for (int i = 1; i <= n; ++ i) res += 1ll * L[i] * R[n - i + 1]; cout << res; 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...