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

用C++,不要用G++!!!

Posted by lzxzy at 2018-09-09 11:40:34 on Problem 2823 and last updated at 2018-09-09 11:41:01
//单调栈
#include <cstdio>
using namespace std;
int n,k,shu,top1,top2,real1,real2;

struct node
{
	int t,shu;
}a[10000005],b[10000005];

struct poj
{
	int a,b;
}ans[10000005];

int main()
{
	scanf("%d%d",&n,&k);
	top1=top2=real1=real2=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&shu);
		while(shu>a[top1].shu&&top1>real1)top1--;
		while(shu<b[top2].shu&&top2>real2)top2--;
		top1++;top2++;
		a[top1].shu=b[top2].shu=shu;
		a[top1].t=b[top2].t=i;
		if(a[real1+1].t<=i-k)real1++;
		if(b[real2+1].t<=i-k)real2++;
		if(i>=k)
		{
			ans[i-k+1].a=a[real1+1].shu;
			ans[i-k+1].b=b[real2+1].shu;
		}
	}
	for(int i=1;i<=n-k+1;i++)printf("%d ",ans[i].b);
	printf("\n");
	for(int i=1;i<=n-k+1;i++)printf("%d ",ans[i].a);
	printf("\n");
	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