hdu4027Can you answer these queries?
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027
区间(单点)更新,区间求和。
1 #include<cstdio> 2 #include<algorithm> 3 #include<cmath> 4 #define lson l,m,rt<<1 5 #define rson m+1,r,rt<<1|1 6 #define ll long long 7 using namespace std; 8 const int maxn=100010; 9 ll f[maxn<<2]; 10 void pushup(int rt) 11 { 12 f[rt]=f[rt<<1]+f[rt<<1|1]; 13 return; 14 } 15 void build(int l,int r,int rt) 16 { 17 f[rt]=0; 18 if(l==r) 19 { 20 scanf("%I64d",&f[rt]); 21 return; 22 } 23 int m=(l+r)>>1; 24 build(lson); 25 build(rson); 26 pushup(rt); 27 } 28 29 void update(int L,int R,int l,int r,int rt) 30 { 31 if(l==r){ 32 f[rt]=sqrt(1.0*f[rt]); 33 return; 34 } 35 if(L<=l&&r<<R&&f[rt]==r-l+1) return; //剪枝 36 int m=(l+r)>>1; 37 if(L<=m) update(L,R,lson); 38 if(R>m) update(L,R,rson); 39 pushup(rt); 40 } 41 42 ll query(int L,int R,int l,int r,int rt) 43 { 44 if(L<=l&&r<=R) return f[rt]; 45 int m=(l+r)>>1; 46 ll ans=0; 47 if(L<=m) ans+=query(L,R,lson); 48 if(R>m) ans+=query(L,R,rson); 49 return ans; 50 } 51 int main() 52 { 53 int n; 54 int cas=0; 55 while(scanf("%d",&n)!=EOF) 56 { 57 build(1,n,1); 58 int m; 59 scanf("%d",&m); 60 61 printf("Case #%d:\n",++cas); 62 for(int i=1;i<=m;i++) 63 { 64 65 int a,b,c; 66 scanf("%d%d%d",&a,&b,&c); 67 int x=max(b,c); 68 int y=min(b,c); 69 if(a==0) update(y,x,1,n,1); 70 else printf("%I64d\n",query(y,x,1,n,1)); 71 } 72 puts(""); 73 } 74 }
转载于:https://www.cnblogs.com/yijiull/p/6619179.html
hdu4027Can you answer these queries?相关推荐
- SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并
Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...
- 线性代数四之动态DP(广义矩阵加速)——Can you answer these queries III,保卫王国
动态DP--广义矩阵加速 SP1716 GSS3 - Can you answer these queries III description solution code [NOIP2018 提高组] ...
- SPOJ GSS2 Can you answer these queries II (线段树离线) - xgtao -
Can you answer these queries II 这是一道线段树的题目,维护历史版本,给出N(<=100000)个数字(-100000<=x<=100000),要求求出 ...
- HDU 4027 Can you answer these queries?(线段树/区间不等更新)
传送门 Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/6576 ...
- HDU 1027 G - Can you answer these queries?
http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Time Limit: 4000/2000 M ...
- GSS2 - Can you answer these queries II
GSS2 - Can you answer these queries II 题意: 给你1e51e51e5 的序列,每次询问区间l到rl到rl到r,每个相同的数只算一次的最大子段和. 思路: 乍一眼 ...
- Can you answer these queries I SPOJ - GSS1 (线段树维护区间连续最大值/最大连续子段和)...
You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defi ...
- Can you answer these queries III (线段树维护最大子段和)
题意: 求一个区间的最大连续和. 0:表示把A[x]改成y 1:表示求[x,y]这个区间的最大连续和. 题解: 线段树维护四个变量. 倒着讲,先来看如何维护这四个变量. summax代表这个区间连续最 ...
- 解题报告:SP1043 GSS4 - Can you answer these queries III(GSS线段树八部曲之三)(区间最大连续子段和)
要注意输入的数据有坑,x可能大于y- 我们可以模块化编程,使得整个代码井井有条 函数可以重名,只要参数不一样就行. 来源 yxc老师的上课板书 然后就是简单的代码了 #include<iostr ...
最新文章
- SLAM 技术之对于扫描精度的影响及改进
- 3 x 10的python表达式_已知 x = [3, 5, 7],那么表达式 x[10:]的值为_学小易找答案
- uchome后台系统配置分析
- USTC English Club Note20211110
- [Java核心技术(卷I)] - vscode手动编译运行继承类
- (八)linux驱动之ioctl的使用
- java 模块化 soa_OSGI与SOA的千丝万缕
- HDF5数据模型介绍及h5py
- java 采集器_使用jsoup来写小说采集器
- C#入门经典.第6版 源代码下载 百度云盘下载
- Selenium实现QQ空间说说自动点赞
- 快速学习法:一年搞定MIT计算机课程
- 西安交通大学学生邮箱设置
- 2022年SCI期刊最新影响因子正式发布
- js获取当前月、上一月和下一月
- 不为人知的腾讯创业史---蜗牛创业网
- 诺基亚的最后机会:没落贵族能否抗衡苹果安卓
- 股市有风险,入市需谨慎,风险和谨慎如何理解?
- java计算机毕业设计ssm校园舆情监控系统tgv13(附源码、数据库)
- pcm格式封装wav