Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

貌似吧,栈模拟的复杂度比直接单调队列略高??还是一样??

Posted by liu_cheng_ao at 2016-10-09 21:48:39 on Problem 3250
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator