hdu 4027 Can you answer these queries? -线段树
来源:互联网 发布:网络消费者品牌形象 编辑:程序博客网 时间:2024/05/19 22:51
题目链接 :点击打开链接
题目要求开根那么再大的一个数不超过十次开根就会变成1,那么此时就不需要再更新了,所以用线段树只需特判这个点就可以了。
题解:
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;typedef long long ll;const int mx=100010;int n,m;ll sum[mx<<2];void push_up(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1];}void build(int l,int r,int rt){ if(l==r){ scanf("%lld",sum+rt); return ; } int m=(l+r)>>1; build(lson); build(rson); push_up(rt);}void update(int l,int r,int rt,int L,int R){ if(sum[rt]==r-l+1) return ; if(l==r){ sum[rt]=sqrt(sum[rt]); return ; } int m=(l+r)>>1; if(L<=m) update(lson,L,R); if(R>m) update(rson,L,R); push_up(rt);}ll query(int l,int r,int rt,int L,int R){ if(l>=L&&R>=r) return sum[rt]; int m=(l+r)>>1; ll ans=0; if(L<=m) ans+=query(lson,L,R); if(R>m) ans+=query(rson,L,R); return ans;}int main(){ int cases=1; while(cin>>n){ build(1,n,1); int q,x,y,t; scanf("%d",&q); printf("Case #%d:\n",cases++); while(q--){ scanf("%d%d%d",&t,&x,&y); if(x>y) swap(x,y); if(t){ printf("%lld\n",query(1,n,1,x,y)); }else{ update(1,n,1,x,y); } } puts(""); } return 0;}
0 0
- HDU 4027 Can you answer these queries? 【线段树】
- HDU 4027 Can you answer these queries 线段树
- hdu 4027(线段树)Can you answer these queries?
- HDU 4027 线段树 Can you answer these queries?
- hdu 4027 线段树 Can you answer these queries?
- HDU 4027 Can you answer these queries?(线段树)
- hdu 4027 Can you answer these queries? 线段树
- hdu 4027 Can you answer these queries? 线段树
- hdu-4027-Can you answer these queries?-线段树
- hdu 4027 Can you answer these queries? 线段树
- HDU 4027 Can you answer these queries? (线段树)
- hdu 4027 Can you answer these queries?(线段树)
- HDU 4027 Can you answer these queries?(线段树)
- HDU 4027 Can you answer these queries ? ( 线段树 )
- Hdu 4027 Can you answer these queries?(线段树)
- hdu 4027 Can you answer these queries? 线段树
- 【HDU】4027 Can you answer these queries? (线段树)
- HDU 4027 Can you answer these queries(线段树)
- 2017年ACM模板(常用)弱渣整理 二、二分
- 在网站建设中一般都需要些什么功能?
- CF
- springMvc直接接收json数据自动转化为Map<String,String>
- Android之Service使用方法:
- hdu 4027 Can you answer these queries? -线段树
- 关于Java中的环境变量配置的
- java虚拟机年轻代的gc
- glib使用平衡二叉树实现读配置文件
- UVA-11078 Open Credit System
- 设计模式之---解释器模式
- 什么是渐进增强?
- HDU 5492 Find a path【DP】
- 小菜鸟学习SpringMVC(二) 注解开发