这道题……
怎么说呢,跟P4333很像,而且那题的数据比这题要强
P4333的链接
我的题解
贴代码
#include<iostream>
using namespace std;
long long st[10000000],n,top=1,ans,m;
int main()
{
cin>>n;
int a;
cin>>st[1];
for(int i=2;i<=n;i++)
{
cin>>a;
if(st[top]>a)
{
top++,ans++,st[top]=a;
}
else
{
int l=1,r=top;
while(l<r)
{
m=(l+r)>>1;
if(r==l+1)m=r;
if(a>=st[m])r=m-1;
else l=m;
}
ans+=top-l+1;
while(top>0&&st[top]<a)top--;
st[++top]=a;
}
}
cout<<ans;
}