Light oj 1082 - Array Queries 【RMQ 裸题】
来源:互联网 发布:阿里云ecs挂载数据盘 编辑:程序博客网 时间:2024/06/06 02:50
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 toJ.
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 index I and J.
Sample Input
Output for Sample Input
2
5 3
78 1 22 12 3
1 2
3 5
4 4
1 1
10
1 1
Case 1:
1
3
12
Case 2:
10
Note
Dataset is huge. Use faster I/O methods.
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <vector>#include <map>#include <string>#include <algorithm>#define MAXN 100000+10#define MAXM 2000+10#define INF 0x3f3f3f3fusing namespace std;int Amin[MAXN][30];int A[MAXN];int N, Q;void RMQ_init(){ for(int i = 1; i <= N; i++) Amin[i][0] = A[i]; for(int j = 1; (1<<j) <= N; j++) { for(int i = 1; i + (1<<j)-1 <= N; i++) Amin[i][j] = min(Amin[i][j-1], Amin[i+(1<<(j-1))][j-1]); }}int query(int L, int R){ int k = 0; while((1<<(k+1)) <= R-L+1) k++; return min(Amin[L][k], Amin[R-(1<<k)+1][k]);}int k = 1;int main(){ int t; scanf("%d", &t); while(t--) { scanf("%d%d", &N, &Q); for(int i = 1; i <= N; i++) scanf("%d", &A[i]); RMQ_init(); int a, b; printf("Case %d:\n", k++); while(Q--) { scanf("%d%d", &a, &b); printf("%d\n", query(a, b)); } } return 0;}
- Light oj 1082 - Array Queries 【RMQ 裸题】
- Light OJ 1082 Array Queries 【RMQ裸题】
- Light OJ 1082 1082 - Array Queries(区间最值)
- Light oj 1082 - Array Queries(区间最小值)
- Light OJ-1082 Array Queries(线段树最值查询)
- light oj 1100 - Again Array Queries
- LightOJ - 1082 Array Queries(RMQ)
- LightOJ 1082 Array Queries RMQ
- light oj 1082 - Array Queries【线段树】最简单的查询最值
- Light OJ-1082 - Array Queries,线段树区间查询最大值,哈哈,水过~~
- light oj 1369 - Answering Queries
- Light OJ 1369 - Answering Queries 【规律】
- Light OJ 1369 Answering Queries (思维)
- 题号未知 , Array Queries 【RMQ】
- lightOJ 1082 Array Queries
- Light OJ 1188 Fast Queries(分块暴力)
- Light OJ 1188 Fast Queries (树状数组离线)
- Light OJ 1082
- GSM与GPRS的区别
- 小型udp读取器,用来简化应用程序间消息的传送
- 遗传算法
- Medical Multistore OpenCart 自适应主题模板 ABC-0150
- 语言自举的哲学思考
- Light oj 1082 - Array Queries 【RMQ 裸题】
- 设计模式(二):难忘一次分享盛宴
- POJ1286 Necklace of Beads【Polya定理】
- hdu 1217 Arbitrage
- quartz定时任务时间设置
- Tortoisesvn找不到系统指定路径
- 在extjs 的tree中联动修改页面,但是页面不出来,还报ct is null或者...is no function
- using gdb to debug c program
- Knockout 学习笔记1 with对象用法需要注意的地方