# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
728702 | MilosMilutinovic | Mountains (NOI20_mountains) | C++14 | 183 ms | 12476 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n,fenv[300005],L[300005];
long long h[300005];
void compress()
{
vector<long long> xs;
for(int i=1;i<=n;i++) xs.push_back(h[i]);
sort(xs.begin(),xs.end());
xs.erase(unique(xs.begin(),xs.end()),xs.end());
for(int i=1;i<=n;i++) h[i]=(int)(lower_bound(xs.begin(),xs.end(),h[i])-xs.begin())+1;
}
void update(int x)
{
for(int i=x;i<=300000;i+=i&-i) fenv[i]+=1;
}
int query(int x)
{
int res=0;
for(int i=x;i>=1;i-=i&-i) res+=fenv[i];
return res;
}
signed main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%lld",&h[i]);
compress();
for(int i=1;i<=n;i++) L[i]=query(h[i]-1),update(h[i]);
for(int i=0;i<=300000;i++) fenv[i]=0;
long long ans=0;
for(int i=n;i>=1;i--) ans+=1ll*L[i]*query(h[i]-1),update(h[i]);
printf("%lld",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |