Can you answer these queries?(线段树之单点更新)
来源:互联网 发布:江西财经大学网络教学 编辑:程序博客网 时间:2024/06/07 23:38
萌萌哒的传送门
因为一个long long 范围内的数开方不会超过10次,所以题目就转化为线段树的单点更新问题.
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <set>#include <queue>#include <vector>#include <cstdlib>#include <algorithm>#define ls u << 1#define rs u << 1 | 1#define lson l, mid, u << 1#define rson mid + 1, r, u << 1 | 1#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;const int M = 1e5 + 100;const int N = 1e7 + 100;ll sum[M << 2];void pushup(int u){ sum[u] = sum[ls] + sum[rs];}void build(int l,int r,int u){ if(l == r){ scanf("%I64d",sum + u); } else { int mid = (l + r) >> 1; build(lson); build(rson); pushup(u); }}void update(int L,int R,int l,int r,int u){ if(sum[u] == (r - l + 1)){ return; } if(l == r){ sum[u] = floor(sqrt((double)sum[u])); } else { int mid = (l + r) >> 1; if(L <= mid) update(L,R,lson); if(R > mid) update(L,R,rson); pushup(u); }}ll query(int L,int R,int l,int r,int u){ if(L <= l && R >= r){ return sum[u]; } else { int mid = (l + r) >> 1; ll res = 0; if(L <= mid) res += query(L,R,lson); if(R > mid) res += query(L,R,rson); return res; }}int main(){ //freopen("in","r",stdin); int n,m,cnt = 0; while(~scanf("%d",&n)){ build(1,n,1); scanf("%d",&m); printf("Case #%d:\n",++cnt); while(m--){ int t,l,r; scanf("%d %d %d",&t,&l,&r); if(l > r) swap(l,r); if(!t) update(l,r,1,n,1); else { printf("%I64d\n",query(l,r,1,n,1)); } } puts(""); } return 0;}
0 0
- Can you answer these queries?(线段树之单点更新)
- HDU4027:Can you answer these queries?(线段树单点更新)
- hdu 4027 Can you answer these queries? 线段树 懒惰标记 单点更新妙用
- T - Can you answer these queries?(单点更新,线段树优化)
- HDU4027:Can you answer these queries?(线段树 单点更新 区间求和)
- HDU 4027 Can you answer these queries?(线段树单点更新)
- spoj Can you answer these queries I(线段树 单点更新 区间查询)
- HDU 4027 Can you answer these queries?(线段树单点更新+询问+神坑)
- HDU4027 Can you answer these queries? (线段树单点更新 +优化)
- Can you answer these queries?+线段树
- Can you answer these queries?(单点更新+标记)
- hdu 4027 Can you answer these queries?(线段树)(单点更新 但需要标记记录剪枝)
- hdu Can you answer these queries? 线段树成段更新
- Can you answer these queries?(线段树,区间更新,更新到点)
- HDU 4027 Can you answer these queries? 【线段树】
- HDU 4027 Can you answer these queries 线段树
- SPOJ/GSS3:Can you answer these queries III(线段树)
- HDU4027 Can you answer these queries? (线段树)
- Android图像处理之Bitmap类
- Metasploit - Loading External Modules
- 分支-18. 求一元二次方程的根*
- 简单的三级联动
- 图标字体化浅谈
- Can you answer these queries?(线段树之单点更新)
- Android学习:资源管理
- 因子
- 猜数字
- php下memcache的应用(三)——linux下php扩展memcached的安装
- 我的VB理解
- Maven安装(Maven学习2)
- APP设计师必上的10个APP图标素材资源站
- 查看java calss文件的jdk版本