Submission #874852

#TimeUsernameProblemLanguageResultExecution timeMemory
87485212345678Mountains (NOI20_mountains)C++17
0 / 100
80 ms15136 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); cout<<i<<' '<<dp[i]<<'\n'; 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...