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表

Posted by liu_cheng_ao at 2016-09-20 21:50:11 on Problem 3264
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>

using namespace std;

int n,q,l,r,lqq,ne2;
int st[17][51000],stmx[20][51000];

int main()
{
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
    {
            scanf("%d",&st[0][i]);
            stmx[0][i]=st[0][i];
    }
    ne2=log((double)n)/log(2.0);
    for(int i=1;i<=ne2;i++)
    {
            int mxj=n-(1<<i)+1,lq=1<<(i-1);
            for(int j=1;j<=mxj;j++)
            {st[i][j]=min(st[i-1][j+lq],st[i-1][j]);
            stmx[i][j]=max(stmx[i-1][j+lq],stmx[i-1][j]);
            }
    }
    for(int i=1;i<=q;i++)
    {
            scanf("%d%d",&l,&r);lqq=log((double)r-l)/log(2.0);
            printf("%d\n",max(stmx[lqq][l],stmx[lqq][r+1-(1<<lqq)])-min(st[lqq][l],st[lqq][r+1-(1<<lqq)]));
    }
    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