Submission #210548

#TimeUsernameProblemLanguageResultExecution timeMemory
210548mayhoubsalehMountains (NOI20_mountains)C++14
100 / 100
560 ms26232 KiB
#include <bits/stdc++.h> #include <string> #define ll long long #define pb push_back #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; map<ll,ll>m; ll ans; const ll maxn=3e5+100; ll n,a[maxn]; ll tr[maxn],lft[maxn]; ll cnt=1; ll sum(ll id){ ll ret=0; for(;id;id-=id&(-id))ret+=tr[id]; return ret; } void add(ll id){ for(;id<=cnt;id+=id&(-id))tr[id]++; } ll qur(ll l,ll r){ if(r==0)return 0; return sum(r)-sum(l-1); } int main() { IOS cin>>n; for(ll i=0;i<n;i++){ cin>>a[i]; m[a[i]]=1; } for(auto &x:m){ x.second=cnt++; } for(ll i=0;i<n;i++){ a[i]=m[a[i]]; //cout<<a[i]<<' '; } cnt--; for(ll i=0;i<n;i++){ lft[i]=qur(1,a[i]-1); add(a[i]); //cout<<lft[i]<<' '; } for(ll i=0;i<n;i++){ ll righ=qur(1,a[i]-1)-lft[i]; ans+=righ*lft[i]; } cout<<ans<<endl; 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...