HDOJ 1754 I Hate It (线段树)
题目:
这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
思路:
tree[rt].w=max(tree[rt*].w,tree[rt*+].w);
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=2e5+;
int n,m,x,y,ans;
int a[maxn];
char op[]; struct node{
int l,r,w;
}tree[maxn<<]; void build(int l,int r,int rt){
tree[rt].l=l;
tree[rt].r=r;
if(l==r){
tree[rt].w=a[l];
return;
}
int mid=(l+r)/;
build(l,mid,rt*);
build(mid+,r,rt*+);
tree[rt].w=max(tree[rt*].w,tree[rt*+].w);
} void update(int rt){
if(tree[rt].l==tree[rt].r){
tree[rt].w=y;
return;
}
int mid=(tree[rt].l+tree[rt].r)/;
if(x<=mid) update(rt*);
else update(rt*+);
tree[rt].w=max(tree[rt*].w,tree[rt*+].w);
}
void query(int rt){
if(tree[rt].l>=x && tree[rt].r<=y){
ans=max(ans,tree[rt].w);
return;
}
int mid=(tree[rt].l+tree[rt].r)/;
if(x<=mid) query(rt*);
if(y>mid) query(rt*+);
} int main(){
while(~scanf("%d%d",&n,&m)){
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
build(,n,);
for(int i=;i<=m;i++){
scanf("%s%d%d",op,&x,&y);
if(op[]=='Q'){
ans=;
query();
printf("%d\n",ans);
}
if(op[]=='U'){
update();
}
}
}
return ;
}
HDOJ 1754 I Hate It (线段树)的更多相关文章
- HDOJ 1754 I Hate It 线段树 第二题
I Hate It Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就 ...
- hdu 1754 I Hate It 线段树 点改动
// hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...
- HDU 1754 I Hate It(线段树之单点更新,区间最值)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 1754 I Hate It 线段树RMQ
I Hate It Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=175 ...
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- HDU 1754 I Hate It(线段树单点替换+区间最值)
I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...
- HDU 1754 I Hate It (线段树)
题意:略. 析:裸的线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include < ...
- 【HDU】1754 I hate it ——线段树 单点更新 区间最值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 1754 I Hate It(线段树区间查询,单点更新)
描述 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感.不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老 ...
- HDU 1754 I Hate It (线段树)
题目链接 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老 ...
随机推荐
- 关于mac 系统如何通过终端 连接linux服务器 并传文件!
首先要打开终端 mac远程链接服务器 输入 : ssh root@xxx.xx.xxx.xx xxx.xx.xxx.xx是端口号 后面会要求你输入password 即可远程连接 mac通过终端给 ...
- mysql清理binlog日志
mysql的binlog日志过多过大,清理过程. 1.查看binlog日志 mysql> show binary logs; +------------------+-----------+ | ...
- 人工神经网络入门(4) —— AFORGE.NET简介
范例程序下载:http://files.cnblogs.com/gpcuster/ANN3.rar如果您有疑问,可以先参考 FAQ 如果您未找到满意的答案,可以在下面留言:) 0 目录人工神经网络入门 ...
- ARM寄存器介绍
ARM处理器共有37个寄存器.其中包括:31个通用寄存器,包括程序计数器(PC)在内.这些寄存器都是32位寄存器.以及6个32位状态寄存器.但目前只使用了其中12位.ARM处理器共有7种不同的处理器模 ...
- Spark源码剖析 - SparkContext的初始化(九)_启动测量系统MetricsSystem
9. 启动测量系统MetricsSystem MetricsSystem使用codahale提供的第三方测量仓库Metrics.MetricsSystem中有三个概念: Instance:指定了谁在使 ...
- MySQLMySql免安装版安装配置
MySql免安装版安装配置,附MySQL服务无法启动解决方案 mysql 5.6.17 绿色版(免安装)安装配置教程 [mysql] # 设置mysql客户端默认字符集 default-charact ...
- 基本数据类型转String,String转基本数据类型
基本数据类型 --> 字符串 1.基本数据类型+"" String s = 5 + ""; 2.使用包装类的静态方法toString(参数),参数是要转化 ...
- 简单备份mysql数据库
对于数据量不大的业务场景,可以每天做全量备份. 实现方式:编写备份数据库脚本,然后在crontab中每天定时执行脚本进行备份. 备份脚本示例: #!/bin/bash #Author: zhangsa ...
- Git学习一:基本用法
git config:配置相关信息 git clone:复制仓库 git init:初始化仓库 git add:添加更新内容到索引中 git diff:比较内容 git status:获取当前项目状况 ...
- Json转Hashtable的转换
json 转换为Hashtable /// <summary> /// Json转Hashtable /// </summary> /// <param name=&qu ...