| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
貌似吧,栈模拟的复杂度比直接单调队列略高??还是一样??#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,h;
int qh[81000],cnt,no[81000];
unsigned long long ans;
void wk(int i)
{
int l=1,r=cnt+1,m;
while(l!=r)
{
m=(l+r)>>1;
if(qh[m]<=h)r=m;else l=m+1;
}
for(int j=l;j<=cnt;j++)
{
ans+=i-no[j]-1;
qh[j]=no[j]=0;
}
cnt=l;no[l]=i;qh[l]=h;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&h);
wk(i);
}
h=0x3f3f3f3f;
wk(n+1);
printf("%u",ans);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator