2015长春网络赛 1007 - The Water Problem(裸线段树)
2015-09-13 18:14
471 查看
The Water Problem
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with a1,a2,a3,...,anrepresenting
the size of the water source. Given a set of queries each containing 2 integers l and r,
please find out the biggest water source between al and ar.
Input
First you are given an integer T(T≤10) indicating
the number of test cases. For each test case, there is a number n(0≤n≤1000) on
a line representing the number of water sources. n integers
follow, respectively a1,a2,a3,...,an,
and each integer is in {1,...,106}.
On the next line, there is a number q(0≤q≤1000) representing
the number of queries. After that, there will be q lines
with two integers l and r(1≤l≤r≤n) indicating
the range of which you should find out the biggest water source.
Output
For each query, output an integer representing the size of the biggest water source.
Sample Input
3 1 100 1 1 1 5 1 2 3 4 5 5 1 2 1 3 2 4 3 4 3 5 3 1 999999 1 4 1 1 1 2 2 3 3 3
Sample Output
100 2 3 4 4 5 1 999999 999999 1由于题目一样,水题#include <map> #include <set> #include <cmath> #include <ctime> #include <queue> #include <vector> #include <cctype> #include <cstdio> #include <string> #include <cstring> #include <sstream> #include <cstdlib> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define pb push_back #define mp make_pair #define fillchar(a, x) memset(a, x, sizeof(a)) #define copy(a, b) memcpy(a, b, sizeof(a)) #define lson rt << 1, l, mid #define rson rt << 1|1, mid + 1, r typedef long long LL; typedef pair<int, int > PII; typedef unsigned long long uLL; template<typename T> void print(T* p, T* q, string Gap = " ") { int d = p < q ? 1 : -1; while(p != q) { cout << *p; p += d; if(p != q) cout << Gap; } cout << endl; } template<typename T> void print(const T &a, string bes = "") { int len = bes.length(); if(len >= 2)cout << bes[0] << a << bes[1] << endl; else cout << a << endl; } const int INF = 0x3f3f3f3f; const int MAXM = 2e5; const int MAXN = 1e3 + 5; int T, n , Sum[MAXN << 2]; void pushup(int rt) { Sum[rt] = max(Sum[rt << 1], Sum[rt << 1|1]); } void build(int rt, int l, int r) { if(l == r){ cin >> Sum[rt]; return; } int mid = (l + r) >> 1; build(lson); build(rson); pushup(rt); } int query(int L, int R, int rt, int l, int r) { if(L <= l && r <= R) { return Sum[rt]; } int mid = (l + r) >> 1; int ret = 0; if(L <= mid) ret = max(ret, query(L, R, lson)); if(R > mid) ret = max(ret, query(L, R, rson)); return ret; } int main(){ //freopen("D://imput.txt", "r", stdin); int l, r, q; cin >> T; while(T --){ cin >> n; build(1, 1, n); cin >> q; while(q --){ cin >> l >> r; cout << query(l, r, 1, 1, n) << endl; } } return 0; }
相关文章推荐
- boost库asio详解8——几个TCP的简单例
- 2015长春网络赛1001 - HDU5433 - Alisha’s Party (模拟)
- http://www.aboutyun.com/thread-6551-1-1.html
- 2015长春网络赛1003(hdu5439)推公式
- 《Unix网络编程》读书笔记
- 【网络】(六)TCP的十一种状态
- Java网络编程 UDP发送与接收数据
- Unix网络编程中的I/O模型
- [PHP学习教程 - 网络]002.获取网页内容(URL Content)
- http-关于application/x-www-form-urlencoded等字符编码的解释说明
- 与三菱Q系列PLC-TCP通信(MC协议)学习总结
- Java网络编程 获取本地主机名称和地址
- HDU 5446 Unknown Treasure (2015年长春赛区网络赛J题)
- Linux C语言程序设计(十九)——基于UDP的网络编程
- 2015.9.13 VIM、权限和网络管理
- 2015长春网络赛小结
- windows网络远程关机重启
- (转)Http学习之使用HttpURLConnection发送post和get请求
- hdu 5442 长春区域赛网络赛 1006 Favorite Donut(后缀数组)
- TCP包服务器接受程序