(线段树 区间查询)The Water Problem -- hdu -- 5443 (2015 ACM/ICPC Asia Regional Changchun Online)
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5443
The Water Problem
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 738 Accepted Submission(s): 591
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
2
3
4
4
5
1
999999
999999
1
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cstdlib>
- #include<queue>
- #include<vector>
- #include<cmath>
- using namespace std;
- #define N 1110
- #define INF 0xffffff
- #define Lson r<<1
- #define Rson r<<1|1
- #define Mid a[r].mid()
- struct node
- {
- int L, R, Max;
- int mid() {return (L+R)/;}
- }a[N*];
- int n, m;
- void BuildTree(int r, int L, int R)
- {
- a[r].L = L, a[r].R = R, a[r].Max = ;
- if(L==R)
- {
- scanf("%d", &a[r].Max);
- return ;
- }
- BuildTree(Lson, L, Mid);
- BuildTree(Rson, Mid+, R);
- a[r].Max = max(a[Lson].Max, a[Rson].Max);
- }
- int Query(int r, int L, int R)
- {
- if(a[r].L==L && a[r].R==R)
- {
- return a[r].Max;
- }
- if(R<=Mid)
- return Query(Lson, L, R);
- else if(L>Mid)
- return Query(Rson, L, R);
- else
- {
- int LMax = Query(Lson, L, Mid);
- int RMax = Query(Rson, Mid+, R);
- return max(LMax, RMax);
- }
- }
- int main()
- {
- int t;
- scanf("%d", &t);
- while(t--)
- {
- int i, L, R;
- scanf("%d", &n);
- BuildTree(, , n);
- scanf("%d", &m);
- for(i=; i<=m; i++)
- {
- scanf("%d%d", &L, &R);
- printf("%d\n", Query(, L, R));
- }
- }
- return ;
- }
(线段树 区间查询)The Water Problem -- hdu -- 5443 (2015 ACM/ICPC Asia Regional Changchun Online)的更多相关文章
- (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )
http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others) Memo ...
- (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)
http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others) ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...
- hdu 5444 Elven Postman(根据先序遍历和中序遍历求后序遍历)2015 ACM/ICPC Asia Regional Changchun Online
很坑的一道题,读了半天才读懂题,手忙脚乱的写完(套上模板+修改模板),然后RE到死…… 题意: 题面上告诉了我们这是一棵二叉树,然后告诉了我们它的先序遍历,然后,没了……没了! 反复读题,终于在偶然间 ...
- HDU 5437 Alisha’s Party (优先队列)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...
- Hdu 5442 Favorite Donut (2015 ACM/ICPC Asia Regional Changchun Online 最大最小表示法 + KMP)
题目链接: Hdu 5442 Favorite Donut 题目描述: 给出一个文本串,找出顺时针或者逆时针循环旋转后,字典序最大的那个字符串,字典序最大的字符串如果有多个,就输出下标最小的那个,如果 ...
- Hdu 5446 Unknown Treasure (2015 ACM/ICPC Asia Regional Changchun Online Lucas定理 + 中国剩余定理)
题目链接: Hdu 5446 Unknown Treasure 题目描述: 就是有n个苹果,要选出来m个,问有多少种选法?还有k个素数,p1,p2,p3,...pk,结果对lcm(p1,p2,p3.. ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU - 5441 (离线+并查集)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5441 题意:给你n,m,k,代表n个城市,m条边,k次查询,每次查询输入一个x,然后让你一个城市对(u,v ...
随机推荐
- Haskell语言学习笔记(28)Data.Map
Map Prelude> import Data.Map as Map Prelude Map> :set -XOverloadedLists Prelude Map> Overlo ...
- c# 7 vs2017 tuple
var unnamed = (42, "The meaning of life"); var anonymous = (16, "a perfect square& ...
- struts2 防止表单重复提交--令牌机制
jsp: action: 配置文件:
- Ubuntu下面网络固定ip
https://jingyan.baidu.com/article/e5c39bf5bbe0e739d7603396.html
- suse11 sp4(虚拟机) 能ping通主机,但是主机ping不通suse虚拟机
sese的防火墙没关. 查看防火墙状态: rcSuSEfirewall2 status(必须是root账户,sudo都不行) 关闭防火墙:rcSuSEfirewall2 stop 事实上,防火墙有时候 ...
- cdoj841-休生伤杜景死惊开 (逆序数变形)【线段树 树状数组】
http://acm.uestc.edu.cn/#/problem/show/841 休生伤杜景死惊开 Time Limit: 3000/1000MS (Java/Others) Memory ...
- Android网络类型判断(2g、3g、wifi)
判断网络类型是wifi,还是3G,还是2G网络,对不同 的网络进行不同的处理,现将判断方法整理给大家,以供参考 说明:下面用到的数据移动2G,联通2G,联通3G,wifi我都已经测试过,暂时手上 ...
- Array Product(模拟)
Array Product http://codeforces.com/problemset/problem/1042/C You are given an array aa consisting o ...
- 归并排序/合并排序c++实现
#include <iostream>#include<string.h> using namespace std;class merges{public:void merge ...
- python之ftp作业【还未完成】
作业要求 0.实现用户登陆 1.实现上传和下载 3.每个用户都有自己的家目录,且只可以访问自己的家目录 4.对用户进行磁盘配额,每个用户的空间不同,超过配额不允许下载和上传 5.允许用户在指定的家目录 ...