hdu 4417 求[l,r]区间内小于v的有多少个
来源:互联网 发布:域名后缀biz什么意思 编辑:程序博客网 时间:2024/05/17 08:37
//hdu 4417 求[l,r]区间内小于v的有多少个////解题思路:////函数式线段树.终于见识了一下这个高大上的数据结构//当出现更新的时候将前面的线段树完整的保存下来,然后将//需要更新的节点复制下来的同时,将其不更新的部分连接到//前面一个线段树上.这样最省空间.并且多了一个性质,就是//两个线段树之间的对应节点满足加减性质.这样就很好啦~~//,记录每个数字出现的次数,再进行加减操作就好啦~~~////感悟:////很高大上的结构,看着还是挺简单,但是想法估计有点难//并且现在只是会裸地...继续加油吧!FIGHTING!!!#include <cstring>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <string>#include <vector>#include <queue>#define For(x,a,b,c) for (int x = a; x <= b; x += c)#define Ffor(x,a,b,c) for (int x = a; x >= b; x -= c)#define cls(x,a) memset(x,a,sizeof(x))using namespace std;typedef long long ll;const double PI = acos(-1.0);const double eps = 1e-9;const int MAX_N = 1e5 + 8;const int INF = 1e9 + 7;const ll MOD = 1e9 + 7;int N,M;int a[MAX_N];int b[MAX_N];struct node{int ls;int rs;int sum;};struct IntravelTree{node p[MAX_N * 20];int root[MAX_N];int Siz;void init(){Siz = 1;}int build(int L,int R){int rt = Siz++;p[rt].sum = 0;if (L == R){return rt;}int M = (L + R) >> 1;p[rt].ls = build(L,M);p[rt].rs = build(M+1,R);return rt;}int update(int rt,int q,int v,int L,int R){int nrt = Siz++;p[nrt] = p[rt];p[nrt].sum += v;if (L == R) return nrt;int M = (L + R) >> 1;if (q <= M)p[nrt].ls = update(p[rt].ls,q,v,L,M);else p[nrt].rs = update(p[rt].rs,q,v,M+1,R);return nrt;}int query(int rtl,int rtr,int q,int L,int R){if (L == R) return p[rtr].sum - p[rtl].sum;int res = 0;int M = (L + R) >> 1;if (q <= M){res += query(p[rtl].ls,p[rtr].ls,q,L,M);}else {res += p[p[rtr].ls].sum - p[p[rtl].ls].sum;res += query(p[rtl].rs,p[rtr].rs,q,M+1,R);}return res;}}it;void input(){scanf("%d%d",&N,&M);For(i,1,N,1){scanf("%d",&a[i]);b[i] = a[i];}sort(b+1,b+N+1);int tot = unique(b + 1 , b + N + 1) - b;b[tot] = INF;it.init();it.root[0] = it.build(1,tot);For(i,1,N,1){a[i] = lower_bound(b + 1, b + tot + 1,a[i]) - b ;it.root[i] = it.update(it.root[i-1],a[i],1,1,tot);}//print();while(M--){int l,r,v;scanf("%d%d%d",&l,&r,&v);l++,r++;int k = upper_bound(b + 1,b + tot + 1, v) - b -1;//cout << k << endl;int ans = 0;if (k > 0){ans = it.query(it.root[l-1],it.root[r],k,1,tot);}printf("%d\n",ans);}}int main(){int t;//freopen("1.in","r",stdin);//freopen("1.out","w",stdout);scanf("%d",&t);int kase = 1;while(t--){printf("Case %d:\n",kase++);input();}}
0 0
- hdu 4417 求[l,r]区间内小于v的有多少个
- hdu 5289 Assignment(给一个数组,求有多少个区间,满足区间内的最大值和最小值之差小于k)
- 中国剩余定理 (求某一区间内有多少个解的问题) HDU X问题
- hdu 4417 划分树加二分 求区间内小于num的数的个数
- hdu 4417 划分树 求一个区间内小于n的数
- Hdu 5790 Prefix(每次查询问你第L个字符串和第R个字符串之间的公共前缀有多少个)
- FFT(快速傅立叶变换)求数组中两两之和小于某个数的有多少个
- hdu 4630 查询[L,R]区间内任意两个数的最大公约数
- HDU 6069 求区间[L,R]每个数的k次方的因子数之和
- 给定r,n求[1,r]内与n互素的个数有多少个?(容斥定理+位运算)
- 求1~r内有多少个数与n互素
- Codeforces-785E-Anton and Permutation(分块区间查询,动态查询[l,r]内小于某个值的元素个数)
- HDU 3874 Necklace&&HDU 3333 Turing Tree(求一些区间l~r中的数去重后的和)
- 区间内有多少个不同的数字(离线树状数组)
- 数位dp 求l-r(10进制) 在k进制中有多少个回文数的模板
- 【主席树】 HDU 4417 Super Mario 区间内小于某值的个数
- hdu 1695 hdu 4135 容斥原理求1-n 区间内与r互质的个数
- 线段树离线处理(区间内出现k次的数有多少个)Codeforces Round #136 (Div. 2)
- ORACLE数据库优化
- poj 2115 C Looooops 【扩展欧几里得】
- 软件测试1
- 普通代码块,静态代码块和构造代码块
- Introduce Intelligence to Your Security Operations
- hdu 4417 求[l,r]区间内小于v的有多少个
- SpriteBuilder中应用智能精灵集之后提示找不到文件的解决
- 心得
- APK反编译二次打包实例-论坛
- HDU 1695 GCD(欧拉函数+容斥原理)
- Dotnetbar Winform 属性备忘
- IE10 CSS Hack
- LeetCode 39: Combination Sum
- uva11111