HDU4027线段树
来源:互联网 发布:暂七师军乐队 知乎 编辑:程序博客网 时间:2024/04/27 03:22
http://acm.hdu.edu.cn/showproblem.php?pid=4027
这道题很玄学呀~我用宏定义输入数据会超时,用scanf(“%d”,&)会超时(原先是%I64)这个坑先留着,以后看看能不能想到其他方法。
因为数据最大2^64,所以最多开方7次数据就变成1了。这时不必再进行更新操作,直接结束递归。树中的判断方法是总和是否等于区间长度。
下面是代码
#include <cstdio>#include <cstring>#include <iostream>#include <cmath>#define lson l, m, rt<<1#define rson m+1, r, rt<<1|1#define N 200000+5#define R (rt<<1|1)#define L (rt<<1)#define lson l,mid,L#define rson mid+1,r,R#define mid (l+r)/2#define INF 0x3f3f3f3f#define mem(arr,a) memset(arr,a,sizeof(arr))#define LL long long int#define sd1(a) scanf("%d",&a)#define sd2(a,b) scanf("%d%d",&a,&b)#define sd3(a,b,c) scanf("%d%d%d",&a,&b,&c)#define pd1(a) printf("%d",a)#define pd2(a,b) printf("%d%d",a,b)#define max(a,b) (a>b?a:b)#define min(a,b) (a<b?a:b)using namespace std;const int maxn = 100010;LL sum[maxn * 4];int n, m;void PushUp(int rt){ sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; return;}void build(int l, int r, int rt){ if (l == r) { scanf("%I64d", &sum[rt]); return; } build(lson); build(rson); PushUp(rt);}void update(int a, int b, int l, int r, int rt){ if (l == r) { sum[rt] = sqrt(1.0 * sum[rt]); return; } if (a <= l && r <= b && sum[rt] == r - l + 1) { return; } if (a <= mid) update(a, b, lson); if (mid < b) update(a, b, rson); PushUp(rt);}LL query(int a, int b, int l, int r, int rt){ if (a <= l && r <= b) { return sum[rt]; } LL ans = 0; if (a <= mid) ans += query(a, b, lson); if (mid < b) ans += query(a, b, rson); return ans;}int main(){ int test = 0; while (scanf("%d", &n) != EOF) { build(1, n, 1); int a, b, c; int x, y; scanf("%d", &m); printf("Case #%d:\n", ++test); while (m--) { scanf("%d%d%d", &a, &b, &c); x = min(b, c); y = max(b, c); if (a == 0) { update(x, y, 1, n, 1); } else { printf("%I64d\n", query(x, y, 1, n, 1)); } } puts(""); } return 0;}
0 0
- hdu4027 线段树
- HDU4027线段树
- hdu4027(线段树)
- hdu4027 线段树单点更新
- hdu4027(线段树的lazy操作)
- 线段树--区间更新区间查询--hdu4027
- hdu4027 线段树成段更新
- HDU4027 Can you answer these queries? (线段树)
- hdu4027 Can you answer these queries? 线段树
- HDU4027:Can you answer these queries?(线段树单点更新)
- 线段树特殊标记hdu4027(网络赛)
- hdu4027-Can you answer these queries?(线段树)
- hdu4027 Can you answer these queries?(线段树)
- [kuangbin带你飞]专题七 线段树 H HDU4027
- HDU4027-Can you answer these queries?(线段树+思路)
- 线段树--hdu4027 Can you answer these queries?
- hdu4027 Can you answer these queries?(线段树)
- HDU4027 Can you answer these queries? (线段树)
- 解决在JDK8中org.aspectj.apache.bcel.classfile.ClassFormatException Invalid byte tag in constant pool: 18
- 从尾到头打印单链表
- IntelliJ IDEA 同一窗口查看多个项目(模块),就像eclipse一样
- android解决app开启瞬间白屏的问题
- Java设计模式笔记之原型模式
- HDU4027线段树
- hdu 1085
- Android 开发,关于依赖库的制作,打包aar,及使用过程
- ZigBee_2530初学笔记
- pyspark + mongodb
- 学习运维——虚拟机管理
- 自动配置ssh公私钥
- RecyclerView加载不同类型的布局
- Oracle数据库的归档模式与非归档模式