HDOJ-1754 I Hate It
来源:互联网 发布:sketch mac汉化破解版 编辑:程序博客网 时间:2024/05/18 00:56
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;#define maxn 200005struct Stu{ int l, r, s;}str[maxn*3];int num[maxn];void Build(int n, int l, int r){ str[n].l =l; str[n].r = r; if(l == r){ str[n].s = num[l]; return ; } int mid = (l + r) / 2; Build(n<<1, l, mid); Build(n<<1|1, mid+1, r); str[n].s = max(str[n<<1].s, str[n<<1|1].s);}void Top(int n, int l, int r, int &s){ if(str[n].l == l && str[n].r == r) { s = max(s, str[n].s); return ; } int mid = (str[n].l + str[n].r) / 2; if(r <= mid){ Top(n<<1, l, r, s); } else if(l > mid){ Top(n<<1|1, l, r, s); } else{ Top(n<<1, l, mid, s); Top(n<<1|1, mid+1, r, s); }}void Update(int n, int a, int b){ if(str[n].l == str[n].r){ str[n].s = b; return ; } int mid = (str[n].l + str[n].r) / 2; if(a <= mid) Update(n<<1, a, b); else Update(n<<1|1, a, b); str[n].s = max(str[n<<1].s, str[n<<1|1].s);}int main(){ //freopen("in.txt", "r", stdin); int n, m; while(cin >> n >> m) { for(int i = 1; i <= n; i++) scanf("%d ", num+i); Build(1, 1, n); char ch; int a, b; for(int i = 1; i <= m; i++) { scanf("%c %d %d ", &ch, &a, &b); if(ch == 'Q') { int s = 0; Top(1, a, b, s); cout << s << endl; } else if(ch == 'U'){ Update(1, a, b); } } } return 0;}
0 0
- HDOJ 1754 I Hate It
- hdoj 1754 I Hate It
- HDOJ 1754 I Hate It
- HDOJ 1754 - I Hate It
- HDOJ 1754 I Hate It
- HDOJ 1754 I Hate It
- HDOJ 1754 I Hate It
- HDOJ 1754 I Hate It
- Hdoj 1754 I hate it
- hdoj 1754 I Hate It
- HDOJ-1754 I Hate It
- hdoj-1754-I Hate It
- hdoj 1754 I Hate It
- HDOJ 1754-I Hate It
- hdoj 1754 I Hate It
- HDU/HDOJ----1754 I Hate It
- HDOJ 1754 I Hate It(线段树)
- hdoj 1754 I Hate It(线段树)
- HUST 1599 (找规律)
- git学习
- Linux 如何查看进程的各线程的CPU占用
- 公共技术点之 Java 反射 Reflection
- 深入FFM原理与实践
- HDOJ-1754 I Hate It
- os send,receive 实现
- Swift UIColor Extension (扩展)
- 二维数组的传参问题!!!
- 获取腾讯企业邮箱通讯录python脚本(带登录功能)
- linux编译器之再谈vim入门
- Linux Vi 删除全部内容,删除某行到结尾,删除某段内容 的方法
- 基础7
- CODE[VS] 1068 乌龟棋