I Hate It HDU
来源:互联网 发布:java string是什么意思 编辑:程序博客网 时间:2024/06/08 14:52
很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
Input
在每个测试的第一行,有两个正整数 N 和 M ( 0
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#define MAXN 800010struct node{ int r,l,nsum;}t[MAXN];int n,m,ans;int num1[MAXN];int max(int a,int b){ return a > b ? a : b;}void build(int l, int r, int i)//建立线段树{ t[i].l = l; t[i].r = r; if(l == r) { t[i].nsum = num1[l]; return ; } int mid = (l+r)/2; build(l, mid, i*2); build(mid+1, r, i*2+1); t[i].nsum = max(t[i*2].nsum, t[i*2+1].nsum);}void update(int x, int c, int i)//在x位置上更新成c{ if (t[i].l == t[i].r) { t[i].nsum = c; return ; } int mid = (t[i].l+t[i].r)/2; if(x > mid) update(x, c, i*2+1); else update(x, c, i*2); t[i].nsum = max(t[i*2].nsum, t[i*2+1].nsum);}void query(int l, int r, int i)//查找该区间上的最大值{ if(t[i].l == l && t[i].r == r) { ans = max(ans, t[i].nsum); return ; } int mid = (t[i].l+t[i].r)/2; if(l > mid) query(l, r, i*2+1); else if(r <= mid) query(l, r, i*2); else { query(l, mid, i*2); query(mid+1, r, i*2+1); }}int main(){ char ch; int x,y; while(~scanf("%d%d",&n,&m)) { for(int i=1; i<=n; i++) { scanf("%d",&num1[i]); } build(1, n, 1); while(m--) { getchar(); scanf("%c%d%d",&ch,&x,&y); if(ch == 'U') { update(x, y, 1); } else if(ch == 'Q') { ans = -99999; query(x, y, 1); printf("%d\n",ans); } } } return 0;}
阅读全文
0 0
- HDU I Hate It
- I Hate It HDU
- I Hate It HDU
- I Hate It (HDU
- I Hate It HDU
- I hate it.hdu
- I Hate It HDU
- I Hate It HDU
- I Hate It HDU
- 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
- MINI2440裸机实验之SDRAM
- 创建一个Redis工具类
- 下面是一个5*5的螺旋矩阵,试编程打印出此形式的n*n(n<10)阶的方阵
- 虚拟机安装步骤
- codevs2298 石子合并(直线形
- I Hate It HDU
- 两个队列实现一个栈
- JSP 九大内置对象
- cookie获取游览器的上次访问时间的代码
- 数组中只出现一次的数字
- [洛谷 1373]小a和uim之大逃离---差值dp
- 基于OpenCv生成蒙太奇马赛克照片
- JVM(一)——JVM体系结构
- 服务端实现跨域访问的三种办法