Submission #339796

#TimeUsernameProblemLanguageResultExecution timeMemory
339796mihai145Mountains (NOI20_mountains)C++14
100 / 100
649 ms27660 KiB
#include <iostream> #include <algorithm> #include <unordered_map> using namespace std; const int NMAX = 3e5; int N; long long v[NMAX + 5], vv[NMAX + 5]; int k; unordered_map <long long, int> norm; int st[NMAX + 5], dr[NMAX + 5]; struct AIB { int n, v[NMAX + 5]; void Reset(int _n) { n = _n; for(int i = 0; i <= n; i++) v[i] = 0; } int Lsb(int x) { return x & (-x); } void Update(int pos, int val) { for(int i = pos; i <= n; i += Lsb(i)) v[i] += val; } int Query(int pos) { int ans = 0; for(int i = pos; i > 0; i -= Lsb(i)) ans += v[i]; return ans; } }; AIB aib; int main() { cin >> N; for(int i = 1; i <= N; i++) { cin >> v[i]; vv[i] = v[i]; } sort(vv + 1, vv + N + 1); for(int i = 2; i <= N; i++) if(vv[i] != vv[i - 1]) norm[vv[i - 1]] = ++k; norm[vv[N]] = ++k; aib.Reset(N); for(int i = 1; i <= N; i++) { st[i] = aib.Query(norm[v[i]] - 1); aib.Update(norm[v[i]], 1); } aib.Reset(N); for(int i = N; i >= 1; i--) { dr[i] = aib.Query(norm[v[i]] - 1); aib.Update(norm[v[i]], 1); } long long sol = 0LL; for(int i = 1; i <= N; i++) sol += 1LL * st[i] * dr[i]; cout << sol << '\n'; 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...