退役后学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的更多相关文章

  1. hdu 1754 线段树(Max+单点修改)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. hdu 1754 Ihate it

    I Hate It Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  3. hdu 1754 I Hate It (splay tree伸展树)

    hdu 1754 I Hate It 其实我只是来存一下我的splay模板的..请大牛们多多指教 #include<stdio.h> #include<string.h> #i ...

  4. hdu 1754 I Hate It (线段树功能:单点更新和区间最值)

    版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...

  5. HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)

    HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...

  6. HDU 1754——I Hate It——————【线段树单点替换、区间求最大值】

    I Hate It Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  7. 线段树(单点更新) HDU 1754 I Hate It

    题目传送门 /* 线段树基本功能:区间最大值,修改某个值 */ #include <cstdio> #include <cstring> #include <algori ...

  8. hdu 1754 I Hate It 线段树 点改动

    // hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...

  9. 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 ...

随机推荐

  1. 文件内容差异对比-python

    上次没精力时候,看了下python自动化运维,给print加了颜色,新鲜哒 今天来写写文件对比 step1:引入difflib库(无需安装,python自带) step2:将文件内容按行分割,spli ...

  2. 回车符号 ‘\r’ 的实际应用

    由于最近开始研究自动化测试 首先是自动定时去下载安装包,需要实时显示进度. 于是了解了进度条相关的方法. 作下记录. 区别 \r 表示将光标的位置回退到本行的开头位置 \n 表示光标从下一行的开头位置 ...

  3. FJoi2017 1月20日模拟赛 交错和(等差数列+rmq)

    [题目描述] 无限循环数字串S由长度为n的循环节s构成.设s为12345(n=5),则数字串S为123451234512345… 设Si为S的第i位数字,在上面的例子中,S1=1,S2=2,S6=1. ...

  4. Spring Tool Suite 安装

    第一步:到http://spring.io/tools/sts/all/上下载对应版本.(此处以博主Windows64位系统为例) 第二步: 进入eclipse,依次点击help-->Insta ...

  5. 【05】JSON笔记

    [05]笔记           尽管有许多宣传关于 XML 如何拥有跨平台,跨语言的优势,然而,除非应用于 Web Services,否则,在普通的 Web 应用中,开发者经常为 XML 的解析伤透 ...

  6. MT6753平台一项目不同手机最低亮度存偏差问题分析过程

    现象: MT6753平台一项目不同手机将背光高度调到最低,最低亮度存偏差问题,有一些亮,有一些暗. 现象较明显. 分析过程: 第一天: 和TCL屏天一起验证,有以下结论: 1.TCL和YASSI模组, ...

  7. [bzoj1070][SCOI2007]修车[ 网络流]

    把每个工人拆成N个点.记为A[i,j]表示第i个工人修倒数第j辆车.每个车跟所有N*M个工人拆出的点连边.流量为1,费用为$time[i,j]*k$.源和每辆车连边,N*M个点和汇连边,流量都为1,费 ...

  8. [codeVS3943] 数学奇才琪露诺

    题目描述 Description 作为上白泽慧音老师的出色弟子,数学奇才琪露诺在算术方面有很深的造诣.今天,codevs有幸请到了这位数学界的奇葩作为本场考试的第一题主考官. 琪露诺喜欢0-9之间的数 ...

  9. nyoj_79_拦截导弹_201403182040

    拦截导弹 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 某国为了防御敌国的导弹袭击,发展中一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到 ...

  10. Crashing Robots POJ 2632 简单模拟

    Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is neede ...