Submission #329148

#TimeUsernameProblemLanguageResultExecution timeMemory
329148poom2904Mountains (NOI20_mountains)C++11
66 / 100
110 ms10988 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long int; int n; bool cmp(const pair<ll,int> a,const pair<ll,int> b) { return a.first<b.first; } vector<int> new_hei(300001,0); vector<int> lower_l(300001,0); vector<int> lower_r(300001,0); vector<ll> fen(300001); void upd(int idx) { for(;idx<=300000;idx+=idx&-idx)fen[idx]++; } ll read(int idx) { ll res=0; for(;idx>0;idx-=idx&-idx)res+=fen[idx]; return res; } int main() { ios_base::sync_with_stdio(false);cin.tie(0); cin>>n; vector<pair<ll,ll> > height(n); for(int i=0;i<n;i++){cin>>height[i].first;height[i].second=i+1;} sort(height.begin(),height.end(),cmp); ll pre=-1,new_h=0; for(int i=0;i<n;) { if(height[i].first!=pre) { new_h++; pre=height[i].first; } new_hei[height[i++].second]=new_h; } fill(fen.begin(),fen.end(),0); for(int i=2;i<=n;i++) { upd(new_hei[i-1]); lower_l[i]=read(new_hei[i]-1); } fill(fen.begin(),fen.end(),0); for(int i=n-1;i>=1;i--) { upd(new_hei[i+1]); lower_r[i]=read(new_hei[i]-1); } ll res=0; for(int i=1;i<=n;i++)res+=lower_l[i]*lower_r[i]; cout<<res; 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...