【线段树】HDU 5443 The Water Problem
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5443
题目大意:
T组数据。n个值,m个询问,求区间l到r里的最大值。(n,m<=1000)
题目思路:
【线段树】
线段树裸题。求区间最大值。
//
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 1004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int t[N<<];
void change(int l,int r,int a,int k,int x)
{
if(a>r || a<l || l>r)return;
if(l==r && l==a){t[k]=x;return;}
change(l,(l+r)/,a,k+k,x);
change((l+r)/+,r,a,k+k+,x);
t[k]=max(t[k+k],t[k+k+]);
}
int query(int l,int r,int a,int b,int k)
{
if(l>r || l>b || r<a)return ;
if(a<=l && r<=b)return t[k];
int mid=(l+r)/,x1,x2;
x1=query(l,mid,a,b,k+k);
x2=query(mid+,r,a,b,k+k+);
return max(x1,x2);
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,l,r,x;
for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d",&n))
{
memset(t,,sizeof(t));
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&x);
change(,n,i,,x);
}
scanf("%d",&m);
for(i=;i<=m;i++)
{
scanf("%d%d",&l,&r);
printf("%d\n",query(,n,l,r,));
}
}
return ;
}
/*
// //
*/
千万不要点
【线段树】HDU 5443 The Water Problem的更多相关文章
- hdu 5443 The Water Problem(长春网络赛——暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java ...
- hdu 5443 The Water Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, ...
- hdu 5443 The Water Problem 线段树
The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDU 5443 The Water Problem (ST算法)
题目链接:HDU 5443 Problem Description In Land waterless, water is a very limited resource. People always ...
- ACM学习历程—HDU 5443 The Water Problem(RMQ)(2015长春网赛1007题)
Problem Description In Land waterless, water is a very limited resource. People always fight for the ...
- HDU 5443 The Water Problem (水题,暴力)
题意:给定 n 个数,然后有 q 个询问,问你每个区间的最大值. 析:数据很小,直接暴力即可,不会超时,也可以用RMQ算法. 代码如下: #include <cstdio> #includ ...
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 敌兵布阵(线段树HDU 1166)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...
- HDU 5832 A water problem (带坑水题)
A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...
随机推荐
- 自己动手写shell之chgrp,chown,chmod
1.chgrp实现 #include <grp.h> #include <unistd.h> void chgrp(char * groupname,char * filena ...
- Linux & Mac curl 命令行使用——POST&GET
http提交一个表单,比較经常使用的是POST模式和GET模式 在curl的命令行下,GET模式什么option都不用.仅仅须要把变量写在url里面就能够了 比方: curl http://www.s ...
- java.lang.Math中的基本方法
java.lang.Math类提供的方法都是static的,“静态引入 ”使得不必每次在调用类方法时都在方法前写上类名: import static java.lang.Mat ...
- ubuntu vim YouComlpeteMe配置
使用vundle安装时,在.vimrc中添加 Plugin 'Valloric/YouCompleteMe' 使用Bundle会安装失败原因未知 YCM编译时附加选项--system-libclang ...
- C++之智能指针
导读 一直对智能指针有一种神秘的赶脚,虽然平时没怎么用上智能指针,也就看过STL中的其中一种智能指针auto_ptr,但是一直好奇智能指针的设计因此,今天看了一下<C++ Primer Plus ...
- Python之路,Day22 - 网站用户访问质量分析监测分析项目开发
Python之路,Day22 - 网站用户访问质量分析监测分析项目开发 做此项目前请先阅读 http://3060674.blog.51cto.com/3050674/1439129 项目实战之 ...
- oracle 添加自增索引
1.添加一个Sequence,此处为ID_SEQUENCE. 2.添加对应表,并设置主键 3.设置触发器 create or replace trigger sys.id_add before ins ...
- Volley框架使用(POST)
需要在MyApplication(继承Application)中配置; public static RequestQueue requestQueue; @Override public void o ...
- mssql的holdlock锁跟索引的关系
表锁tablock是会给表所有数据附加共享锁,但是只是当前语句有效,语句执行完毕,锁释放,而不会持续到事务结束,而tablockX表锁是持续到事务结束的锁 holdlock锁,锁定的范围会根据wher ...
- oracle特殊字符的ascii值