Submission #216900

#TimeUsernameProblemLanguageResultExecution timeMemory
216900quocnguyen1012Mountains (NOI20_mountains)C++14
100 / 100
189 ms14216 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 3e5 + 5; int BIT[maxn]; void upd(int i, int v) { for(; i < maxn; i += i & -i) BIT[i] += v; } int sum(int i) { int res = 0; for(; i; i -= i & -i) res += BIT[i]; return res; } signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); #endif // LOCAL int n; cin >> n; vector<ll> a(n); vector<int> l(n), r(n); vector<ll> val; for(auto & x : a) cin >> x; val = a; sort(val.begin(), val.end()); val.erase(unique(val.begin(), val.end()), val.end()); for(auto & x: a){ x = lower_bound(val.begin(), val.end(), x) - val.begin() + 1; } for(int i = 0; i < n; ++i){ l[i] = sum(a[i] - 1); upd(a[i], 1); } for(auto & x : a) upd(x, -1); ll res = 0; for(int i = n - 1; i >= 0; --i){ res += 1ll * sum(a[i] - 1) * l[i]; upd(a[i], 1); } cout << res; }
#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...