HDU 1754 I Hate It【线段树】
来源:互联网 发布:用友软件 西安 编辑:程序博客网 时间:2024/05/29 12:01
题目链接
题目意思
给你n个学生的成绩然后m个询问,Q时询问学生A到B的最高成绩,U时将A学生的成绩改为B
解题思路
一道简单的线段树题,具体的看代码吧!
代码部分
#include <iostream>#include <stdio.h>#include <string.h>#define lchild left,mid,root<<1#define rchild mid+1,right,root<<1|1using namespace std;const int maxn=200000;int Max[maxn<<2];///更新线段树节点void push_up(int root){ Max[root]=max(Max[root<<1],Max[root<<1|1]);}///构建线段树void build(int left,int right,int root){ if(left==right) { scanf("%d",&Max[root]); return; } int mid=(left+right)>>1; build(lchild); build(rchild); push_up(root);}///更改操作void updata(int aim,int num,int left,int right,int root){ if(left==right) { Max[root]=num; return; } int mid=(left+right)>>1; if(aim<=mid) updata(aim,num,lchild); else updata(aim,num,rchild); push_up(root);}///查询操作int query(int L,int R,int left,int right,int root){ if(L<=left&&right<=R) return Max[root]; int mid=(left+right)>>1; int ans=0; if(L<=mid) ans=max(ans,query(L,R,lchild)); if(R>mid) ans=max(ans,query(L,R,rchild)); return ans;}int main(){ int n,m,n1,n2; string str; while(~scanf("%d%d",&n,&m)) { build(1,n,1); while(m--) { cin>>str; if(str[0]=='Q') { scanf("%d%d",&n1,&n2); printf("%d\n",query(n1,n2,1,n,1)); } else { scanf("%d%d",&n1,&n2); updata(n1,n2,1,n,1); } } } return 0;}
阅读全文
1 0
- HDU 1754 I Hate It 线段树
- [hdu] 1754 I hate it -- 线段树
- hdu 1754 -- I Hate It (线段树)
- HDU 1754 I Hate It 线段树
- 线段树 hdu 1754 I Hate It
- HDU 1754 I Hate It(线段树)
- hdu 1754 (线段树)I Hate It
- hdu-1754 I Hate It 线段树
- HDU--1754 -- I Hate It [线段树]
- 【线段树】hdu 1754 I hate it
- hdu - 1754 I Hate It(线段树)
- HDU--1754--I Hate It--线段树
- HDU-1754 I Hate It 线段树
- hdu 1754 I Hate It 线段树
- HDU-1754-I Hate It(线段树)
- HDU 1754 I Hate It (线段树)
- hdu 1754 I hate it(线段树)
- 【HDU】 1754 I Hate It 线段树
- 基于Druid的数据库分片实现
- UI设计线框图工具大全,达人必备
- 浏览器连接不上网络但是qq等服务能联网的解决方法
- serialVersionUID
- 第30天:DOM对象操作
- HDU 1754 I Hate It【线段树】
- 【安全牛学习笔记】端口扫描(二)
- Java基础学习一
- spring-session使用配置(分布式共享session配置)
- QQmlComponent加载component
- 文章标题
- 短实习---Java方法(基础知识)
- 国家版权局严令,音乐产业将面临新一轮洗牌
- 微信小程序生成携带参数的小程序码