hdoj 4325 Flowers 线段树+离散化
hdoj 4325 Flowers 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4325 思路: 直接线段树,按照花的开放区间的大小建树,要注意虽然花的周期数据可能会达到1e9,这样的话线段树开四倍时不可能的。但是我们可以看到一共可能的数据时N行,那么每行两个数,再开4倍的区间。计算下来,在离散化的帮助下,我们只需要开8*N被的线段树即可。 另外询问的数据也需要放入离散化的范围,如果不这样做,有可能在询问时使用lower_bound函数会导致数据的改变,询问的原数据发生变化。 eg:1~3 7~10 询问6,结果应该时0,但因为lower_bound的原因询问时使用7,得到结果1。etc. 代码: #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <math.h> using namespace std; const int maxn = 1e5+5; struct node { int l,r,sum,lazy; inline void update(int val) { lazy+=val; sum+=val; } } tr[maxn*8]; int a[maxn],b[maxn],c[maxn<<1