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 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老 ...
随机推荐
- day-03(js)
回顾: css: 层叠样式表 作用: 渲染页面 提供工作效率,将html和样式分离 和html的整合 方式1:内联样式表 通过标签的style属性 <xxx style="...&qu ...
- 简单BootLoader
目录 简单BootLoader 概述 NOR与NAND启动 链接脚本规划 初始化规划 参数设置 title: 简单BootLoader tags: linux date: 2018-09-28 23: ...
- Java插件之Jrebel
Jrebel是干嘛的?当你在Java Web的项目中修改一些代码的时候(成员代码),想要生效必须重启服务器.但是每次修改代码都得重启服务器?重启着时间很长的,太麻烦了. Jrebel隆重出场,它可以使 ...
- NSGA-II入门C1
NSGA-II入门C1 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献1 参考文献2 白话多目标 多目标中的目标是个瓦特? 多目标即是优化问题中的优化目标在3个及以上,一般这些优化的 ...
- python第三次周末大作业
''' s18第三周周末⼤作业 模拟博客园系统: 1. 启动程序, 显⽰菜单列表 菜单: 1. 登录 2. 注册 3. ⽂章 4. ⽇记 5. 退出 2. ⽤户输入选项, ⽂章和⽇记必须在登录后才可以 ...
- IIS 为应用程序池提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误的解决方法
系统环境:Windows Server 2008 R2 64位, IIS 7.0 错误信息: 为应用程序池提供服务的进程在与 Windows Process Activation Service 通信 ...
- CentOS在VirtualBox虚拟机中网络配置
1. 宿主机网络参数 2. 右键设置,对虚拟机进行设置网络 3.虚拟机 vi /etc/sysconfig/network-scripts/ifcfg-eth1 打开该配置文件 eth0 ...
- Chrome DevTools: Color tricks in the Elements Panel
shift + click to change the color format Tip one The Colour Platters are customeised for you .they s ...
- extern "C" 含义
extern "C" 被 extern 限定的函数或变量是 extern 类型的 被 extern "C" 修饰的变量和函数是按照 C 语言方式编译和链接的 e ...
- Shell编程(七)函数
1. 函数开始 #!/bin/bash foo() { echo "Function foo is called"; } echo "-=start=-" fo ...