线段树i hate it
来源:互联网 发布:淘宝psn点卡会被ban吗 编辑:程序博客网 时间:2024/06/05 01:11
I Hate It
Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 70 Accepted Submission(s) : 24
这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
5 61 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 2 9Q 1 5
5659[hint]Huge input,the C function scanf() will work better than cin[/hint]
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define lson l,m,rt*2//左子树 父节点rt表示区间[l,r],左子树rt*2表示的区间[l,l+r/2]
#define rson m+1,r,rt*2+1//右子树 父节点rt表示区间[l,r],右子树rt*2+1[l+r/2+1,r]
#define inf 222222*4
int tree[inf];
int max(int a,int b)
{
if(a<b) return b;
return a;
}
void pushup(int rt)
{
tree[rt]=max(tree[rt*2],tree[rt*2+1]);//最大值
}
void build(int l,int r,int rt)
{
if(l==r)
{
scanf("%d",&tree[rt]);
return;
}
int m=(l+r)/2;
build(lson);
build(rson);
pushup(rt);
}
void update(int p,int sc,int l,int r,int rt)//位置 改成这个数
{
if(l==r)
{
tree[rt]=sc;
return;
}
int m=(l+r)/2;
if(p<=m) update(p,sc,lson);
else update(p,sc,rson);
pushup(rt);
}
int query(int ll,int rr,int l,int r,int rt)
{
if(ll<=l&&r<=rr)
return tree[rt];
int m=(l+r)/2;
int ret=0;
if(ll<=m) ret=max(ret,query(ll,rr,lson));
if(rr>m) ret=max(ret,query(ll,rr,rson));
return ret;
}
int main()
{
int n,mm,a,b;
string s;
while(cin>>n>>mm)
{
build(1,n,1);
while(mm--)
{
cin>>s;
scanf("%d%d",&a,&b);
if(s=="Q")
cout<<query(a,b,1,n,1)<<endl;
else
update(a,b,1,n,1);
}
}
}
- I Hate It (线段树)
- 线段树:I Hate It
- i hate it 线段树
- I Hate It 【线段树】
- I Hate It---线段树
- I hate it --线段树
- I Hate It (线段树)
- 线段树i hate it
- I Hate It(线段树)
- I hate it HDU【线段树】
- 线段树--【HDU I Hate It】
- HDU 1754 I Hate It 线段树
- [hdu] 1754 I hate it -- 线段树
- hdu 1754 -- I Hate It (线段树)
- HDU 1754 I Hate It 线段树
- POJ 1745 I HATE IT(线段树)
- HDU1754 I Hate It,线段树
- 线段树hdu1754 I Hate It
- 20170907cvte第一道编程题
- EBS采购申请创建
- 模拟实现strcmp
- 643. Maximum Average Subarray I
- Requirejs高级应用(六):模块无法加载错误的解决办法
- 线段树i hate it
- Ubuntu14.04安装PyCharm
- org.hibernate.MappingException: Unknown entity
- 一般系统论的基本概念
- 【爬虫】BeautifulSoup解析网页
- 存储过程
- 注释及不同语言中的注释
- 逻辑思维1
- petalinux 2015.4&& 2016.2安装指南