Submission #874853

#TimeUsernameProblemLanguageResultExecution timeMemory
87485312345678Mountains (NOI20_mountains)C++17
100 / 100
170 ms19400 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=3e5+5; ll n, h[nx], t, dp[nx], res; vector<ll> v; struct fenwick { ll d[nx]; void add(int idx) { for (int i=idx; i<nx; i+=(i&-i)) d[i]++; } ll query(int idx) { ll res=0; for (int i=idx; i>0; i-=(i&-i)) res+=d[i]; return res; } } l, r; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) cin>>h[i], v.push_back(h[i]); sort(v.begin(), v.end()); for (int i=1; i<=n; i++) { int idx=lower_bound(v.begin(), v.end(), h[i])-v.begin()+1; dp[i]=l.query(idx-1); l.add(idx); } for (int i=n; i>=1; i--) { int idx=lower_bound(v.begin(), v.end(), h[i])-v.begin()+1; res+=dp[i]*r.query(idx-1); r.add(idx); } 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...