九度oj 题目1544:数字序列区间最小值
来源:互联网 发布:ubuntu 搭建视频服务器 编辑:程序博客网 时间:2024/06/05 10:48
- 题目描述:
给定一个数字序列,查询任意给定区间内数字的最小值。
- 输入:
输入包含多组测试用例,每组测试用例的开头为一个整数n(1<=n<=100000),代表数字序列的长度。
接下去一行给出n个数字,代表数字序列。数字在int范围内。
下一行为一个整数t(1<=t<=10000),代表查询的次数。
最后t行,每行给出一个查询,由两个整数表示l、r(1<=l<=r<=n)。
- 输出:
对于每个查询,输出区间[l,r]内的最小值。
大二暑假做过的。。。。。我现在能记得啊???明天翻翻大白再来a吧。。。
看了没有超过5分钟,然后开写,然后
九度挂了,到时候再来提交吧。。。
#include <iostream>
#include <queue>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <sstream>
#include <cstring>
using namespace std;
int nums[100001];
int dp[100001][20];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
{
scanf("%d",&nums[i]);
}
for(int i=1;i<=n;i++)
{
dp[i][0]=nums[i];
}
for(int j=1;(1<<j)<=n;j++)
{
for(int i=1;i+(1<<j)-1<=n;i++)
{
dp[i][j]=min(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
}
}
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
int l,r;
scanf("%d %d",&l,&r);
int k=-1;
while((1<<(k+1))<=(r-l+1))
k++;
printf("%d\n",min(dp[l][k],dp[r-(1<<k)+1][k]));
}
}
return 0;
}
- 九度oj 题目1544:数字序列区间最小值
- 九度OJ 1544 数字序列区间最小值
- 九度OJ 1544 数字序列区间最小值
- 九度 1544 数字序列区间最小值
- 九度OJ题目1554:区间问题
- 九度 oj 题目1554:区间问题
- 九度OJ 题目1089:数字反转
- 九度OJ 题目1115:数字求和
- 九度oj题目1106:数字之和
- 九度OJ 题目1089:数字反转
- 九度OJ,题目1089:数字反转
- 九度OJ 题目1115:数字求和
- 九度 oj 题目1089:数字反转
- 九度数字序列区间最小值
- 九度OJ—题目1011:最大连续子序列
- 九度OJ 题目1011:最大连续子序列
- 九度OJ 题目1077:最大序列和
- 九度OJ 题目1011:最大连续子序列
- 23、Mapper解析之基于注解的总体过程
- ffmpeg参数
- Python 多进程 —— 共享数据
- 创建和销毁对象
- python 中UnicodeEncodeError 错误
- 九度oj 题目1544:数字序列区间最小值
- uScript插件学习(三)——用户指南(自定义节点与事件)
- JS中阻止事件冒泡实例
- 24、映射器注册器MapperRegisty
- 01背包
- MAC下安装与配置MySQL
- 【Web前端】Vue.js 项目中遇到的一些问题汇总
- django1.8以上的版本怎么显示网站的 favicon.ico 图标
- 25、Result解析之ResultMapping介绍