51nod 1174 区间中最大的数(送盾题)

时间:2024-01-03 09:54:56
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
51nod 1174 区间中最大的数(送盾题) 收藏
51nod 1174 区间中最大的数(送盾题) 关注
给出一个有N个数的序列,编号0 - N - 1。进行Q次查询,查询编号i至j的所有数中,最大的数是多少。
例如: 1 7 6 3 1。i = 1, j = 3,对应的数为7 6 3,最大的数为7。(该问题也被称为RMQ问题)
Input
第1行:1个数N,表示序列的长度。(2 <= N <= 10000)
第2 - N + 1行:每行1个数,对应序列中的元素。(0 <= S[i] <= 10^9)
第N + 2行:1个数Q,表示查询的数量。(2 <= Q <= 10000)
第N + 3 - N + Q + 2行:每行2个数,对应查询的起始编号i和结束编号j。(0 <= i <= j <= N - 1)
Output
共Q行,对应每一个查询区间的最大值。
Input示例
5
1
7
6
3
1
3
0 1
1 3
3 4
Output示例
7
7
3
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio> #define INF 0x7fffffff
using namespace std; int i,j,n,s[],maxn,Q;
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
cin>>n;
for(i=;i<n;++i)
cin>>s[i];
cin>>Q;
int u,v;
while(Q--)
{
cin>>u>>v;
maxn=-INF;
for(i=u;i<=v;++i)
maxn=max(maxn,s[i]);
cout<<maxn<<endl;
}
return ;
}