显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#define syy myson
using namespace std;
const int INF=100000;
int n,q,h[50010],a,b,minn,maxn,ans,i,j;
int Main()
{
freopen("lineup.in","r",stdin);freopen("lineup.out","w",stdout);
scanf("%d%d",&n,&q);
for(i=1;i<=n;i++)
scanf("%d",&h[i]);
for(i=1;i<=q;i++)
{
minn=INF;maxn=-INF;
scanf("%d%d",&a,&b);
for(j=a;j<=b;j++)
{
if(minn>h[j])minn=h[j];
if(maxn<h[j])maxn=h[j];
}
ans=maxn-minn;
printf("%d",ans);
}
return 0;
}
int main(){;};
int syy=Main();