//Accepted    14796 KB    453 ms
 //划分树
 //把查询的次数m打成n,也是醉了一晚上!!!
 //二分l--r区间第k大的数和h比较
 #include <cstdio>
 #include <cstring>
 #include <iostream>
 #include <queue>
 #include <cmath>
 #include <algorithm>
 using namespace std;
 /**
   * This is a documentation comment block
   * 如果有一天你坚持不下去了,就想想你为什么走到这儿!
   * @authr songt
   */
 ;
 struct node
 {
     int val[imax_n];
     int num[imax_n];
 }f[];
 int a[imax_n];
 int sorted[imax_n];
 int n,m;
 void build(int t,int l,int r)
 {
     if (l==r) return ;
     ;
     ;
     ;
     for (int i=l;i<=r;i++)
     if (f[t].val[i]<sorted[mid]) isame--;
     int ln=l;
     ;
     for (int i=l;i<=r;i++)
     {
         if (i==l)
         {
             f[t].num[i]=;
         }
         ];

         if (f[t].val[i]<sorted[mid])
         {
             f[t].num[i]++;
             f[t+].val[ln++]=f[t].val[i];
         }
         else if (f[t].val[i]>sorted[mid])
         {
             f[t+].val[rn++]=f[t].val[i];
         }
         else
         {
             if (isame>same)
             {
                 same++;
                 f[t].num[i]++;
                 f[t+].val[ln++]=f[t].val[i];
             }
             else
             {
                 f[t+].val[rn++]=f[t].val[i];
             }
         }
     }
     build(t+,l,mid);
     build(t+,mid+,r);
 }
 int query(int t,int l,int r,int a,int b,int k)
 {
     if (l==r) return f[t].val[l];
     ;
     int s,ss;
     if (a==l)
     {
         ss=;
         s=f[t].num[b];
     }
     else
     {
         ss=f[t].num[a-];
         s=f[t].num[b]-ss;
     }

     if (s>=k)
     {
         a=l+ss;
         b=l+ss+s-;
         ,l,mid,a,b,k);
     }
     else
     {
         int b1=a-l-ss;
         -s;
         a=mid++b1;
         b=mid+b1+b2;
         ,mid+,r,a,b,k-s);
     }
 }
 int x,y,h;
 void slove()
 {
     build(,,n);
     ;i<=m;i++)
     {
         scanf("%d%d%d",&x,&y,&h);
         x++;
         y++;
         ,r=y-x+;
         ;
         ;
         while (l<=r)
         {
             mid=(l+r)/;
             ,,n,x,y,mid);
             //printf("pre :l=%d r=%d mid=%d t=%d\n",l,r,mid,t);
             ;
             else
             {
                 ans=mid;
                 l=mid+;
             }
             //printf("l=%d r=%d t=%d\n",l,r,t);
         }
         printf("%d\n",ans);
     }
 }
 int main()
 {
     int T;
     ;
     scanf("%d",&T);
     while (T--)
     {
         scanf("%d%d",&n,&m);
         ;i<=n;i++)
         {
             scanf("%d",&a[i]);
             f[].val[i]=sorted[i]=a[i];
         }
         sort(sorted+,sorted+n+);
         printf("Case %d:\n",++t);
         slove();
     }
     ;
 }

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. Selenium Grid Configuration

    Start Hub and Node with Json config 1. Start Hub with json config file title HubWebDriver java -jar ...

  2. centos7 使用 omnibus包安装方式,安装 gitlab7.4

    centos7 使用 omnibus包安装方式,安装 gitlab7.4 1: gitlab是一个开源的软件,类似于github.com那样的git代码管理仓库: 官网 https://about.g ...

  3. worker中加载本地文件报错的解决方案

    如果在一个swf的主线程中加载文件时,报安全沙箱的错误, 网上有诸多的解决方案.但是如果在一个worker中加载本地文件报类似如下的错误: *** 安全沙箱冲突 *** SecurityError: ...

  4. 指针转换(C# 编程指南)

    原文地址:https://msdn.microsoft.com/zh-cn/library/etb4xxec.aspx 下表显示了预定义的隐式指针转换.隐式转换可能在多种情形下发生,包括调用方法时和在 ...

  5. 3D正方体

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. (02)odoo自定义模块

    * 官方建议模块骨架    --------------------------    addons/<my_module_name>/                 │─ __init ...

  7. MyBatis实体类映射文件模板

      <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC " ...

  8. HDUOJ--汉诺塔II

    汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  9. Unique Paths II [LeetCode]

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  10. hadoop主节点(NameNode)备份策略以及恢复方法

    link:http://jiajun.iteye.com/blog/809125 一.dits和fsimage 首先要提到两个文件edits和fsimage,下面来说说他们是做什么的. 集群中的名称节 ...