无题
2015-08-20 18:16
267 查看
问题
Given an array with N elements, indexed from 1 to N. Now you will be given some queries in the form I J, your task is to find the minimum value from index I to J.
Input
Input starts with an integer T (≤ 5), denoting the number of test cases.
The first line of a case is a blank line. The next line contains two integers N (1 ≤ N ≤ 105), q (1 ≤ q ≤ 50000). The next line contains N space separated integers forming the array. There integers
range in [0, 105].
The next q lines will contain a query which is in the form I J (1 ≤ I ≤ J ≤ N).
Output
For each test case, print the case number in a single line. Then for each query you have to print a line containing the minimum value between indexI and J.
Sample Input
2
5 3
78 1 22 12 3
1 2
3 5
4 4
1 1
10
1 1
Sample Output
Case 1:
1
3
12
Case 2:
10
//这是超时的
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; int a[100100],b[100100]; int main() { int t,T=0; scanf("%d",&t); while(t--) { int n,m,x,y; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",&a[i]); printf("Case %d:\n",++T); while(m--) { int j=1; for(int i=1;i<=n;i++) b[j++]=a[i]; scanf("%d%d",&x,&y); sort(b+x,b+y+1); printf("%d\n",b[x]); } } return 0; }
相关文章推荐
- php中$this->是什么意思
- Struts学习笔记——01
- CoreAnimation(CA)
- MR案例:Reduce-Join
- Android性能优化典范 - 第3季
- 表格显示问题
- NYOJ 364 田忌赛马(贪心)
- 【php】如何提高网页加载速度?
- eclipse导入项目,项目名出现红叉的情况
- android 网络请求图片,返回值为空的解决办法
- 机房收费系统个人重构版:暮然回首,灯火阑珊
- recommender systems
- 监听ContentProvider的数据变化
- shell 带参数脚本
- 头文件与源文件
- ubuntu 查看版本
- Android性能优化典范
- ViewPage和Fragment上 实现BadgeView消息提醒(仿旧微信)
- VBScript中处理浮点数相减的精度问题
- PAT 1053. Path of Equal Weight (30)