Submission #339794

#TimeUsernameProblemLanguageResultExecution timeMemory
339794mihai145Mountains (NOI20_mountains)C++14
24 / 100
691 ms11372 KiB
#include <iostream> #include <set> #include <map> using namespace std; const int NMAX = 3e5; int N, v[NMAX + 5]; set <int> xs; int k; map <int, 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]; xs.insert(v[i]); } while(!xs.empty()) { int val = *xs.begin(); xs.erase(xs.begin()); norm[val] = ++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 = 0; 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...