I Hate It
来源:互联网 发布:linux查看home下用户 编辑:程序博客网 时间:2024/06/15 21:24
I Hate It - HDU 1754 线段树
国际惯例中文题目不需要解释题意。
思路:也是个水体,直接裸线段树就可以,没有什么需要注意的地方。写的时候有一个小错误就是刚开始我在本地运行的时候发现Q 1 5一直是零,结果发现是build函数没有写到main里去。
AC代码:
//// main.cpp// L//// Created by LucienShui on 2017/5/24.// Copyright © 2017年 LucienShui. All rights reserved.//#include <iostream>#include <algorithm>#include <set>#include <string>#include <vector>#include <queue>#include <map>#include <iomanip>#include <cstdio>#include <cstring>#include <cmath>#include <cctype>#define memset(a,b) memset(a,b,sizeof(a))#define il inline#define ull unsigned long longusing namespace std;const int MAXN=200005;int node[MAXN<<2],a[MAXN];#define ls (u<<1)#define rs (u<<1|1)il void build(int u, int left, int right);il void update(int u, int left, int right, int ai, int num);il int query(int u, int left, int right, int begin, int end);il void read(int n);il void solve(int n, int m);int main (){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);#endif // ONLINE_JUDGE int n,m; while(~scanf("%d%d",&n,&m)) { read(n); build(1,1,n); solve(n,m); } return 0;}il void build(int u, int left, int right) { if(left == right) node[u] = a[left]; else { int mid = (left + right) >> 1; build(ls, left, mid); build(rs, mid+1, right); node[u] = max(node[ls],node[rs]); }}il void update(int u, int left, int right, int ai, int num) { if(left == right) { node[u] = num; return ; } int mid = (left + right) >> 1; if(ai<=mid) update(ls,left,mid,ai,num); else update(rs,mid+1,right,ai,num); node[u] = max(node[ls],node[rs]);}il int query(int u, int left, int right, int begin, int end) { if(begin <= left && right <= end) return node[u]; int mid = (left + right) >> 1; if(end <= mid) return query(ls, left, mid, begin, end); else if(begin > mid) return query(rs, mid+1, right, begin, end); else return max(query(ls, left, mid, begin, end),query(rs, mid+1, right, begin, end));}il void read(int n) { for(int i=1 ; i<=n ; i++) scanf("%d",a+i);}il void solve(int n, int m) { char c; int a,b; while(m--) { scanf(" %c%d%d",&c,&a,&b); if(c=='Q') printf("%d\n",query(1,1,n,a,b)); else update(1,1,n,a,b); }}
阅读全文
0 0
- I Hate It
- hdu1754 I Hate It
- HDU1754 I Hate It
- BIT1083 I Hate It
- HDU1754:I Hate It
- HDU1754--I Hate It
- HDU1754 I hate it
- I Hate It tzc
- hdu_1754 I Hate It
- hdu1754 I Hate It
- HDU1754:I Hate It
- I Hate It
- hdu1754 I Hate It
- I Hate It
- I Hate It
- hdu1754 I Hate It
- hdu1754 I Hate It
- hdu1754 I Hate It
- sql的left(a,b)与right(a,b)函数
- LoadRunner安装注意事项
- “集体智慧编程”之第九章:高阶分类-核方法与SVM
- HttpServetRequest读取body只能一次的问题
- Construct Binary Tree from Preorder and Inorder Traversal
- I Hate It
- php文件打开老是自动下载
- LoadRunner之VuGen录制脚本
- 2017年5月反思
- linux下表空间相关查询及操作
- 1007. 素数对猜想 (20)
- CocoaPods 更新慢、失败的解决方法
- 添加聚集索引后高效分页查询的效率
- 何时不应该使用Python