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;
using ll = long long int;
int n;
vector<ll> height(300001);
vector<int> lower_l(300001,0);
vector<int> lower_r(300001,0);
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>height[i];
vector<ll> tem;
for(int i=2;i<=n;i++)
{
tem.insert(upper_bound(tem.begin(),tem.end(),height[i-1]),height[i-1]);
lower_l[i]=lower_bound(tem.begin(),tem.end(),height[i])-tem.begin();
}
tem.clear();
for(int i=n-1;i>=1;i--)
{
tem.insert(upper_bound(tem.begin(),tem.end(),height[i+1]),height[i+1]);
lower_r[i]=lower_bound(tem.begin(),tem.end(),height[i])-tem.begin();
}
ll res=0;
for(int i=1;i<=n;i++)res+=lower_l[i]*lower_r[i];
cout<<res;
return 0;
}
# | 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... |