退役后学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. CCF201604-1 折点计数 java(100分)

    试题编号: 201604-1 试题名称: 折点计数 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 给定n个整数表示一个商店连续n天的销售量.如果某天之前销售量在增长,而后一天 ...

  2. Django加载静态文件失败,已解决

    1.css文件以及js文件要放在static目录下,static和templates属于同级目录 2.在Django项目的同名项目文件的setting.py中,最后添加静态文件夹static目录路径 ...

  3. Python介绍以及Python 优缺点

    Python是先编译成字节码,然后在解释执行的一门语言,而不是单纯的解释型语言 Python应用场景: Web应用开发. 操作系统管理,服务器运维的自动化脚本, 网络爬虫 科学计算 桌面软件 游戏 服 ...

  4. kata练习题

    This time no story, no theory. The examples below show you how to write function accum: Examples: ac ...

  5. How to read and write multiple files in Python?

    Goal: I want to write a program for this: In a folder I have =n= number of files; first read one fil ...

  6. NOIP2018提高组省一冲奖班模测训练(一)

    比赛链接 https://www.51nod.com/contest/problemList.html#!contestId=72&randomCode=147206 这次考试的题非常有质量 ...

  7. JS权威指南笔记1

    1.JavaScript数据类型可分为两种:原始类型和对象类型.原始类型下又包括数字.字符串和布尔值,以及null和undefined这两个特殊的:对象是属性的集合,且每个属性都有自己的"名 ...

  8. 设置idea快速生成doc comment

    在eclipse中快速生成方法的doc comment快捷键是Alt+Shift+J, 而在idea中没有对应的快捷键,但是能实现相似的功能. 1.在方法上面输入/** 然后回车就可以生成注释了. 2 ...

  9. iOS消息推送原理和实现总结

    一.消息推送原理: 在实现消息推送之前先提及几个于推送相关概念,如下图:1. Provider:就是为指定IOS设备应用程序提供Push的服务器,(如果IOS设备的应用程序是客户端的话,那么Provi ...

  10. Hadoop2.0之YARN

    YARN(Yet Another Resource Negotiator)是Hadoop2.0集群中负责资源管理和调度以及监控运行在它上面的各种应用,是hadoop2.0中的核心,它类似于一个分布式操 ...