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 ...
随机推荐
- power coefficient calculation -- post processing
input: unscaled moment of one bladeoutput: power coefficient of a 3-blades wind/tidal turbine matlab ...
- redis—持久化
Redis持久化 概述 Redis的强大性能很大程度上都是因为所有数据都是存储在内存中的,然而当Redis重启后,所有存储在内存中的数据将会丢失,在很多情况下是无法容忍这样的事情的.所以,我们需要将内 ...
- BZOJ 1834 Luogu P2604 [ZJOI2010]网络扩容 (最小费用最大流)
题目连接: (luogu) https://www.luogu.org/problemnew/show/P2604 (bzoj) https://www.lydsy.com/JudgeOnline/p ...
- 【Codeforces 979B】Treasure Hunt
[链接] 我是链接,点我呀:) [题意] 每次你可以将一个字符变成一个不同于本身的字符. 每个人需要改变n次(且不能不改变) 设每个人的字符串中出现次数最多的字符出现的次数为cnt[0~2] 问你谁的 ...
- chrome源代码目录结构简介(版本4.1.249.1059)
为了对庞大的源码项目进行分析,先对源码目录树作一个简单的介绍,粗略的了解一下各个模块的功能分布情况,chrome源代码src目录下的结构如下图: app:该目录下的代码主要是和各个操作系统平台相关的应 ...
- my first emacs custom key binding
(defun comment-this-level () (interactive) (move-beginning-of-line 1) (set-mark-command nil) (fo ...
- QT .pro文件的学习收获
1. 载pro文件预定义宏: CONFIG(debug,debug|release){ DEFINES+=__DEBUG__ }else{ DEFINES+=__RELEASE__ macx:DEST ...
- 洛谷—— P2149 [SDOI2009]Elaxia的路线
https://www.luogu.org/problem/show?pid=2149 题目描述 最近,Elaxia和w的关系特别好,他们很想整天在一起,但是大学的学习太紧张了,他们 必须合理地安排两 ...
- HDFS2.0之简单总结
新特性 NameNode支持HA 命名空间支持分区(Federation) 支持ViewFS 支持目录快照 支持权限ACL 支持缓存指定的文件 QJM实现名字节点HA (图片来源互联网) 命名空间分区 ...
- Spring mvc 时间转换
http://www.cnblogs.com/ssslinppp/p/4600043.html