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

用一维的ST算法比用deque的单调队列还快!!!!

Posted by leeleeon at 2014-01-21 09:49:36 on Problem 2823
由于查询区间长度固定,所以ST可以省掉一维
测试结果吓尿我了,比用deque的单调队列还快。。。
是我单调队列写渣了吗。。。。
CODE:
#include<cstdio>

const int maxn=1010000;
int n,m,d[maxn],dx[maxn],di[maxn],i,j;

inline int max(int a,int b)
{ return a>b?a:b; }
inline int min(int a,int b)
{ return a<b?a:b; }
int main() {
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++) scanf("%d",d+i);
	for(i=0;i<n;i++) dx[i]=di[i]=d[i];
	for(j=1;j*2<m;j*=2)
		for(i=0;i+j<n;i++) {
			dx[i]=max(dx[i],dx[i+j]);
			di[i]=min(di[i],di[i+j]);
		}
	for(i=0;i+m<=n;i++)
		printf("%d ",min(di[i],di[i+m-j]));
	printf("\n");
	for(i=0;i+m<=n;i++)
		printf("%d ",max(dx[i],dx[i+m-j]));
	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