1. //Accepted 14796 KB 453 ms
  2. //划分树
  3. //把查询的次数m打成n,也是醉了一晚上!!!
  4. //二分l--r区间第k大的数和h比较
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <iostream>
  8. #include <queue>
  9. #include <cmath>
  10. #include <algorithm>
  11. using namespace std;
  12. /**
  13. * This is a documentation comment block
  14. * 如果有一天你坚持不下去了,就想想你为什么走到这儿!
  15. * @authr songt
  16. */
  17. ;
  18. struct node
  19. {
  20. int val[imax_n];
  21. int num[imax_n];
  22. }f[];
  23. int a[imax_n];
  24. int sorted[imax_n];
  25. int n,m;
  26. void build(int t,int l,int r)
  27. {
  28. if (l==r) return ;
  29. ;
  30. ;
  31. ;
  32. for (int i=l;i<=r;i++)
  33. if (f[t].val[i]<sorted[mid]) isame--;
  34. int ln=l;
  35. ;
  36. for (int i=l;i<=r;i++)
  37. {
  38. if (i==l)
  39. {
  40. f[t].num[i]=;
  41. }
  42. ];
  43.  
  44. if (f[t].val[i]<sorted[mid])
  45. {
  46. f[t].num[i]++;
  47. f[t+].val[ln++]=f[t].val[i];
  48. }
  49. else if (f[t].val[i]>sorted[mid])
  50. {
  51. f[t+].val[rn++]=f[t].val[i];
  52. }
  53. else
  54. {
  55. if (isame>same)
  56. {
  57. same++;
  58. f[t].num[i]++;
  59. f[t+].val[ln++]=f[t].val[i];
  60. }
  61. else
  62. {
  63. f[t+].val[rn++]=f[t].val[i];
  64. }
  65. }
  66. }
  67. build(t+,l,mid);
  68. build(t+,mid+,r);
  69. }
  70. int query(int t,int l,int r,int a,int b,int k)
  71. {
  72. if (l==r) return f[t].val[l];
  73. ;
  74. int s,ss;
  75. if (a==l)
  76. {
  77. ss=;
  78. s=f[t].num[b];
  79. }
  80. else
  81. {
  82. ss=f[t].num[a-];
  83. s=f[t].num[b]-ss;
  84. }
  85.  
  86. if (s>=k)
  87. {
  88. a=l+ss;
  89. b=l+ss+s-;
  90. ,l,mid,a,b,k);
  91. }
  92. else
  93. {
  94. int b1=a-l-ss;
  95. -s;
  96. a=mid++b1;
  97. b=mid+b1+b2;
  98. ,mid+,r,a,b,k-s);
  99. }
  100. }
  101. int x,y,h;
  102. void slove()
  103. {
  104. build(,,n);
  105. ;i<=m;i++)
  106. {
  107. scanf("%d%d%d",&x,&y,&h);
  108. x++;
  109. y++;
  110. ,r=y-x+;
  111. ;
  112. ;
  113. while (l<=r)
  114. {
  115. mid=(l+r)/;
  116. ,,n,x,y,mid);
  117. //printf("pre :l=%d r=%d mid=%d t=%d\n",l,r,mid,t);
  118. ;
  119. else
  120. {
  121. ans=mid;
  122. l=mid+;
  123. }
  124. //printf("l=%d r=%d t=%d\n",l,r,t);
  125. }
  126. printf("%d\n",ans);
  127. }
  128. }
  129. int main()
  130. {
  131. int T;
  132. ;
  133. scanf("%d",&T);
  134. while (T--)
  135. {
  136. scanf("%d%d",&n,&m);
  137. ;i<=n;i++)
  138. {
  139. scanf("%d",&a[i]);
  140. f[].val[i]=sorted[i]=a[i];
  141. }
  142. sort(sorted+,sorted+n+);
  143. printf("Case %d:\n",++t);
  144. slove();
  145. }
  146. ;
  147. }

hdu4417 划分树+二分的更多相关文章

  1. HDU-4417 Super Mario,划分树+二分!

    Super Mario 这个题也做了一天,思路是很清晰,不过二分那里写残了,然后又是无限RE.. 题意:就是查询区间不大于k的数的个数. 思路:裸划分树+二分答案.将区间长度作为二分范围.这个是重点. ...

  2. sdut 2610:Boring Counting(第四届山东省省赛原题,划分树 + 二分)

    Boring Counting Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述     In this problem you a ...

  3. SDIBT 3237 Boring Counting( 划分树+二分枚举 )

    http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3237 Problem H:Boring Counting Time Limit: 3 Sec  ...

  4. HDU 4417 划分树+二分

    题意:有n个数.m个询问(l,r,k),问在区间[l,r] 有多少个数小于等于k. 划分树--查找区间第k大的数.... 利用划分树的性质.二分查找在区间[l,r]小于等于k的个数. 假设在区间第 i ...

  5. HDU 4417 - Super Mario ( 划分树+二分 / 树状数组+离线处理+离散化)

    题意:给一个数组,每次询问输出在区间[L,R]之间小于H的数字的个数. 此题可以使用划分树在线解决. 划分树可以快速查询区间第K小个数字.逆向思考,判断小于H的最大的一个数字是区间第几小数,即是答案. ...

  6. 【划分树+二分】HDU 4417 Super Mario

    第一次 耍划分树.. . 模板是找第k小的 #include <stdio.h> #include <string.h> #include <stdlib.h> # ...

  7. 13年山东省赛 Boring Counting(离线树状数组or主席树+二分or划分树+二分)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 2224: Boring Counting Time Limit: 3 Sec   ...

  8. HDU 4417 Super Mario(划分树+二分)

    题目链接 #include <cstdio> #include <cstring> #include <algorithm> using namespace std ...

  9. poj 2104:K-th Number(划分树,经典题)

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 35653   Accepted: 11382 Ca ...

随机推荐

  1. java 多线程4(死锁)

    死锁现象: 死锁原因: 1.存在两个或两个以上的线程. 2.存在两个或两个或两个以上的共享资源. 死锁现象解决的方案: 没有方案只能尽量避免.

  2. Java 中String常用方法

    java中String的常用方法 1.length() 字符串的长度 例:char chars[]={'a','b'.'c'}; String s=new String(chars); int len ...

  3. LaTeX内容总结

    欢迎关注我的社交账号: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://gith ...

  4. text-overflow:ellipsis实现超出隐藏时省略号显示

    text-overflow:ellipsis;要达到的效果是:文字超出容器宽度时,文字被隐藏的文字用省略号代替.所以该属性只能用于块状元素或行内块元素中,对行内元素是不起作用的. 一般和white-s ...

  5. Linux基础: 挂载镜像文件(Mount & ISO)

    ISO/Ghost 镜像文件概念(裸机安装,无光驱安装,跨平台安装) ISO是镜像文件:所谓镜像文件其实和ZIP压缩包类似,它将特定的一系列文件按照一定的格式制作成单一的文件,以方便用户下载和使用,例 ...

  6. jsp有关resquest与session和application的区别和相似性

    1. request 的setAttribute与getAttribute方法一般都是成对出现的,首先通过setAttribute方法设置属性与属性值,然后通过 getAttribute方法根据属性获 ...

  7. ZigZag Conversion [LeetCode]

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  8. 20145236 《Java程序设计》第7周学习总结

    20145236 <Java程序设计>第7周学习总结 教材学习内容总结 第十三章 时间与日期 认识时间与日期 时间的度量 格林威治标准时间GMT 格林威治标准时间的正午是太阳抵达天空最高点 ...

  9. Jquery操作select小结

    每次操作select都要查资料,干脆总结一下. 为select设置placeholder <select class="form-control selOP" placeho ...

  10. C#学习笔记思维导图 一本书22张图

    阅读的书是<21天学通C#>博客中有下载 看看总结之后的模块 全部文件 初步展示 数据存储 继承模块 暂时就这些吧 全部思维导图22张打包下载