HDU 1754 线段树-I Hate It
来源:互联网 发布:程序员转管理 编辑:程序博客网 时间:2024/06/17 02:45
题意:
中文题目,不解释了。
题解:
本题使用线段树做,目标是求最大值,因为每次操作知识修改其中一项的值,所以也可以用树状数组做,我用的是线段树。
#include <iostream>#include <stdio.h>#include <string.h>#include <cmath>#define MAXN 200000+10using namespace std;int Max[4*MAXN];int ql,qr,p,v;inline void build(int r,int L, int R){ if(L == R) scanf("%d",&Max[r]); else { int M = (L+R)/2; build(r*2,L,M); build(r*2+1,M+1,R); Max[r] = max(Max[r*2],Max[r*2+1]); }}inline void update(int r, int L, int R){ int M = (L+R)/2; if(L == R) Max[r] = v; else { if(p <= M) update(r*2,L,M); else update(r*2+1,M+1,R); Max[r] = max(Max[r*2],Max[r*2+1]); }}inline int query(int r, int L, int R){ int ans = -1; int M = (L+R)/2; if(ql <= L && R <= qr) return Max[r]; if(qr <= M) return query(r*2,L,M); else if(ql > M) return query(r*2+1,M+1,R); else ans = max(query(r*2,L,M),query(r*2+1,M+1,R)); return ans;}int main(){ int n,m; int a,b; char op[2]; while(~scanf("%d%d",&n,&m)) { build(1,1,n); for(int i = 1; i <= m; i++) { scanf("%s%d%d",op,&a,&b); if(op[0] == 'Q') { ql = a; qr = b; cout << query(1,1,n) << endl; } else { p = a; v = b; update(1,1,n); } } } return 0;}
0 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 线段树
- JDBC学习笔记----环境配置及连接MySQL
- 数据导出excel
- Java各种获得路径方式
- MySQL---数据库从入门走向大神系列(十五)-Apache的DBUtils框架使用
- EAS界面数据关联
- HDU 1754 线段树-I Hate It
- Android Studio 扫描二维码并解析跳转
- MySQL的GROUP_CONCAT()函数的使用
- 循环统计表格数量,单价总和
- linux下SVN服务器的搭建及使用
- HDU 5831 Rikka with Parenthesis II
- VC中CDockablePane使用心得
- MySQL基本概念
- Mac OSX Android源码编译-环境搭建、源码下载、源码编译、导入Android Studio