HDU 1754 Java
退役后学java...
裸线段树
//By SiriusRen
import java.util.*;
import java.math.*;
public class Main{
public static void build(int l,int r,int pos,int []tree,int []score){
if(l==r){tree[pos]=score[l];return;}
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
build(l,mid,lson,tree,score);build(mid+1,r,rson,tree,score);
tree[pos]=Math.max(tree[lson],tree[rson]);
}
public static void insert(int l,int r,int pos, int num,int wei,int []tree){
if(l==r){tree[pos]=wei;return;}
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
if(mid<num)insert(mid+1,r,rson,num,wei,tree);
else if(mid>=num)insert(l,mid,lson,num,wei,tree);
tree[pos]=Math.max(tree[lson],tree[rson]);
}
public static int query(int l,int r,int pos,int L,int R,int []tree){
if(l>=L&&r<=R)return tree[pos];
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
if(mid<L)return query(mid+1,r,rson,L,R,tree);
else if(mid>=R)return query(l,mid,lson,L,R,tree);
else return Math.max(query(l,mid,lson,L,R,tree),query(mid+1,r,rson,L,R,tree));
}
public static void main(String args[]){
int []score=new int[200005];
int []Tree=new int[3500000];
Scanner in=new Scanner(System.in);
while(in.hasNextInt()){
int n=in.nextInt(),m=in.nextInt();
for(int i=1;i<=n;i++)score[i]=in.nextInt();
build(1,n,1,Tree,score);
for(int i=1;i<=m;i++){
String p=in.next();
if(p.equals("Q")){
int jyx=in.nextInt(),jyy=in.nextInt();
int jy=query(1,n,1,jyx,jyy,Tree);
System.out.println(jy);
}
else{
int jyx=in.nextInt(),jyy=in.nextInt();
insert(1,n,1,jyx,jyy,Tree);
}
}
}
}
}
HDU 1754 Java的更多相关文章
- hdu 1754 线段树(Max+单点修改)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 1754 Ihate it
I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- hdu 1754 I Hate It (splay tree伸展树)
hdu 1754 I Hate It 其实我只是来存一下我的splay模板的..请大牛们多多指教 #include<stdio.h> #include<string.h> #i ...
- hdu 1754 I Hate It (线段树功能:单点更新和区间最值)
版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDU 1754——I Hate It——————【线段树单点替换、区间求最大值】
I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- 线段树(单点更新) HDU 1754 I Hate It
题目传送门 /* 线段树基本功能:区间最大值,修改某个值 */ #include <cstdio> #include <cstring> #include <algori ...
- hdu 1754 I Hate It 线段树 点改动
// hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...
- hdu 1754 I Hate It (模板线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=1754 I Hate It Time Limit: 9000/3000 MS (Java/Others) M ...
随机推荐
- docker插件
import docker c = docker.Client(base_url='unix://var/run/docker.sock',version='1.15',timeout=10) pri ...
- python3接口测试某个模块的很多接口有的用post有的用get
没啥好说的,啊哈哈 大神提示可以判断下用post还是get,但是加到哪里合适呢?仔细看认真看 耶耶耶
- 关于python字典中文显示的处理办法
最近工作中遇到字典包含中文,显示\uxxxx的问题,怎么转换都无法输入正常的中文:{"gc": "\u4eba\u751f\u7f8e\u597d", &quo ...
- BZOJ 4094 USACO 2013 Dec. Optimal Milking
线段树 每个节点保存4个值,both表示左右端点都取,neither表示左右端点都不取,left表示只取左端点,right表示只取右端点. 维护的特殊姿势: $cur$的$both=max(ls.l+ ...
- QQ帐户的申请与登陆
QQ帐户的申请与登陆 实现QQ新帐户申请和老帐户登陆的简化版功能.最大挑战是:据说现在的QQ号码已经有10位数了. 输入格式: 输入首先给出一个正整数N(≤10^5,随后给出N行指令.每行指令的格式为 ...
- Spring的Java配置方式
Java配置是Spring4.x推荐的配置方式,可以完全替代xml配置. 1 @Configuration 和 @Bean Spring的Java配置方式是通过 @Configuration ...
- H - Tickets
Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a ...
- SiteMesh2-示例工程
了解SiteMesh的最佳方法是使用它.假设SiteMesh设置在您的Web应用程序中,本教程将展示如何掌握SiteMesh最强大的方面,如下所示装饰页面: 效果发生在第2步,其中Menu.jsp页面 ...
- 【CV论文阅读】Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
由RCNN到FAST RCNN一个很重要的进步是实现了多任务的训练,但是仍然使用Selective Search算法来获得ROI,而FASTER RCNN就是把获得ROI的步骤使用一个深度网络RPN来 ...
- Android Studio VS Eclipse (还在用Eclipse?你OUT了!)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990).谢谢支持! 公司派来一个去美国參加完AnDevCon大会的来给我们分享大会上学习的内容. AnDevC ...