退役后学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. APUE 文件IO

    文件 IO 记录书中的重要知识和思考实践部分 Unix 每个文件都对应一个文件描述符(file descriptor),为一个非负整数,一个文件可以有多个fd, 后面所有与文件(设备,套接字等)有关操 ...

  2. React组件设计技巧

    React组件设计 组件分类 展示组件和容器组件 展示组件 容器组件 关注事物的展示 关注事物如何工作 可能包含展示和容器组件,并且一般会有DOM标签和css样式 可能包含展示和容器组件,并且不会有D ...

  3. 解决Python打包exe控制台无法粘贴问题

    使用pyinstaller打包生成可执行exe文件后,发现启用input()接受键盘输入时窗口无法粘贴也无法右键,找了好久终于找到问题所在: 一是通过右键单击控制台主题边框在弹出的菜单中选择编辑.粘贴 ...

  4. 【tips】xadmin - django第三方后台管理系统

    Django 为大家提供了一个完善的后台管理系统—admin,但是这个后台管理系统总体来说不太适合国人的习惯,所以有大神就使用 bootstrap 和 jQuery,为我们开发了一个第三 方的 Dja ...

  5. x component of 2nd stokes wave--- C code

    * Source code The following is a C code for x component of 2nd stokes wave ××××××××××××××××××××× /*s ...

  6. Keil uVision “已停止工作”

    之前一直受这个问题的困扰,但是因为只是下载程序,下载镜像文件完事就算了.随便keil挂掉. 今天要调试程序,发现开启调试keil就挂掉了,烦. 解决办法参见: http://218.244.144.1 ...

  7. BZOJ 3747 洛谷 3582 [POI2015]Kinoman

    [题解] 扫描线+线段树. 我们记第i部电影上次出现的位置是$pre[i]$,我们从$1$到$n$扫描,每次区间$(pre[i],i]$加上第i部电影的贡献$w[f[i]]$,区间$[pre[pre[ ...

  8. [bzoj1044][HAOI2008][木棍分割] (二分+贪心+dp+队列优化)

    Description 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍被分成了很多段,要求满足总长度最大的一段长 ...

  9. 表格头部header固定

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. C语言试题

    C语言试题 [说明]: 1.本试题中不考虑头文件引用问题(假定已经包含正确的头文件),C语言的标准函数都可用: 2.如果不特别说明,假定程序运行环境为:操作系统Windows 2000, VC6.0编 ...