线段树 HDU 4027 Can you answer my question?
来源:互联网 发布:mac百度云怎么分享链接 编辑:程序博客网 时间:2024/05/01 20:53
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027
代码风格:www.notonlysuccess.com
题目大意:区间求平方根,求区间和
算法:线段树
思路:更新到底
注意:考虑求和的x > y的情况
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;#define lson l,m, rt << 1#define rson m+1, r, rt << 1 | 1#define mid int m= (l+r) >> 1int vis[898989];__int64 cnt[898989];void build(int l,int r, int rt){if(l == r){scanf("%I64d", &cnt[rt]);if(cnt[rt] == 0 || cnt[rt] == 1)vis[rt] = 1;return ;}mid ;build(lson);build(rson);cnt[rt] = cnt[rt << 1] + cnt[rt << 1 | 1];}void update(int L, int R, int l, int r, int rt){if(vis[rt])return ;if(l == r){cnt[rt] = sqrt(cnt[rt]);if(cnt[rt] == 1)vis[rt] = 1;return ;}mid ;if(L <= m)update(L, R, lson);if(m < R) update(L, R, rson);cnt[rt] = cnt[rt << 1] + cnt[rt << 1 | 1];vis[rt] = vis[rt << 1] && vis[rt << 1 | 1];}__int64 query(int L, int R, int l, int r, int rt){if(L <= l && r <= R){return cnt[rt];}mid ;__int64 ret = 0;if(L <= m)ret += query(L, R, lson);if(m < R)ret += query(L, R, rson);return ret ;}int main(){int n, T;int ica = 1;while(scanf("%d", &n) != EOF){printf("Case #%d:\n", ica ++);memset(vis, 0, sizeof(vis));memset(cnt, 0, sizeof(cnt));build(1, n, 1);int op;int a, b, m;scanf("%d", &m);while(m --){scanf("%d", &op);scanf("%d%d", &a, &b);if(b < a ){int t = a;a = b;b = t;}if(op == 1)printf("%I64d\n", query(a, b ,1, n, 1));elseupdate(a, b, 1, n, 1);}printf("\n");}return 0;}
- 线段树 HDU 4027 Can you answer my question?
- 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? (线段树)
- Node.js从入门到深入——Node.js配置开发
- srand()以及rand()函数用法
- poj 1511 Invitation Cards
- java中的IO整理
- git学习笔记
- 线段树 HDU 4027 Can you answer my question?
- 七夕夜、离别,涵情经河岸
- 第八章 流 08_PrintIO
- Linux C多线程编程
- 与文字相拥 舞尽人间芳华
- 中国知名IT企业的资料
- 简单的比较C语言下交换a,b数值的代码效率
- Intent 和 Intent Filter
- android spinner点击android.view.WindowManager$BadTokenException: Unable to add window token is not va