HDU 1754 I Hate It
来源:互联网 发布:我没有说话 知乎 编辑:程序博客网 时间:2024/06/14 10:08
I Hate It
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 64646 Accepted Submission(s): 25109
Problem Description
很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。
这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
Input
本题目包含多组测试,请处理到文件结束。
在每个测试的第一行,有两个正整数 N 和 M ( 0
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<math.h>using namespace std;#define Max 220000char str[10];int num[Max],value,a,res,n;struct node{ int left; int right; int score;} no[Max*4];void build(int l,int r,int i){ no[i].left=l; no[i].right=r; if(l==r) { no[i].score=num[l]; return; } int mid=(l+r)>>1; build(l,mid,2*i); build(mid+1,r,2*i+1); no[i].score=max(no[i*2].score,no[i*2+1].score);}void modify(int l,int r,int num){ if(no[num].left==no[num].right) { no[num].score=value; return; } int mid=(no[num].left+no[num].right)/2; if(a<=mid) { modify(l,r,num*2); } else { modify(l,r,num*2+1); } no[num].score=max(no[num*2].score,no[num*2+1].score);}int query(int start,int end,int i){ int mid=(no[i].left+no[i].right)/2; if(start==no[i].left&&end==no[i].right) { return no[i].score; } else if(end<=mid) { query(start,end,i*2); } else if(start>mid) { query(start,end,i*2+1); } else { int a1=query(start,mid,i*2); int b1=query(mid+1,end,i*2+1); return a1>b1?a1:b1; }}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { int i; for(i=1; i<=n; i++) { scanf("%d",&num[i]); } build(1,n,1); while(m--) { getchar(); scanf("%s",str); scanf("%d%d",&a,&value); if(strcmp(str,"U")==0) { modify(1,n,1); } else { int ans=query(a,value,1); printf("%d\n",ans); } } } return 0;}
代码二:
#include <cstdio> #include <algorithm> using namespace std; #define lson l , m , rt << 1 #define rson m + 1 , r , rt << 1 | 1 const int maxn = 222222; int MAX[maxn<<2]; void PushUP(int rt) { MAX[rt] = max(MAX[rt<<1] , MAX[rt<<1|1]); } void build(int l,int r,int rt) { if (l == r) { scanf("%d",&MAX[rt]); return ; } int m = (l + r) >> 1; build(lson); build(rson); PushUP(rt); } void update(int p,int sc,int l,int r,int rt) { if (l == r) { MAX[rt] = sc; return ; } int m = (l + r) >> 1; if (p <= m) update(p , sc , lson); else update(p , sc , rson); PushUP(rt); } int query(int L,int R,int l,int r,int rt) { if (L <= l && r <= R) { return MAX[rt]; } int m = (l + r) >> 1; int ret = 0; if (L <= m) ret = max(ret , query(L , R , lson)); if (R > m) ret = max(ret , query(L , R , rson)); return ret; } int main() { int n , m; while (~scanf("%d%d",&n,&m)) { build(1 , n , 1); while (m --) { char op[2]; int a , b; scanf("%s%d%d",op,&a,&b); if (op[0] == 'Q') printf("%d\n",query(a , b , 1 , n , 1)); else update(a , b , 1 , n , 1); } } 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
- 关于delphi的PChar, PWideChar, pAnsiChar
- Google Chrome调试js代码
- linux c 编程实战:进程控制总结(四)
- PHP7 微信支付回调失败 解决
- 移动应用开发技术过多,该如何做选择
- HDU 1754 I Hate It
- C++ & Python 多线程笔记
- AndroidStudio 动态修改版本名称
- css布局-两列,左边宽度自适应,右边固定宽度200px
- NSDateFormatter 格式说明
- Storm学习笔记-集群环境安装部署
- Android中实现拨打电话、发送短信、响铃、震动和获取当前时间
- MySql 5.6 版本 2016-07 修改配置文件解决中文乱码问题
- Redis实现微博用户的关注关系