题目链接

题目让求 L R区间 不大于H 的数有多少

数据太大需要离散化

#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
int a[maxn],root[maxn],tot,n,m;
vector<int>q;
struct ac{
   int va,l,r;
}tre[maxn*];
void init(){
  memset(root,,sizeof(root));
  memset(tre,,sizeof(tre));
  tot=;q.clear();
}
int getid(int x){
   ;
}
void updata(int l,int r,int& x,int in,int z){
   tre[++tot]=tre[in];
   tre[tot].va++;
   x=tot;
   if(l==r) return ;
   ;
   if(z>mid){
       updata(mid+,r,tre[x].r,tre[in].r,z);
   }else{
       updata(l,mid,tre[x].l,tre[in].l,z);
   }
}
int query(int x,int y,int l,int r,int z){
   if(x==y) return(tre[r].va-tre[l].va);
   ;
   if(z<=mid){
      return query(x,mid,tre[l].l,tre[r].l,z);
   }
   int ans=tre[tre[r].l].va-tre[tre[l].l].va;
   ,y,tre[l].r,tre[r].r,z));
}
int main(){
   ;
   cin>>t;
   while(t--){
      scanf("%d%d",&n,&m);
      init();
      ;j<=n;j++){
         scanf("%d",&a[j]);
         q.push_back(a[j]);
      }
      sort(q.begin(),q.end());
      q.erase(unique(q.begin(),q.end()),q.end());
      int len=q.size();
      ;j<=n;j++){
         int x=getid(a[j]);
         updata(,len,root[j],root[j-],x);
      }
      printf("Case %d:\n",cnt++);
      ;j<m;j++){
         int l,r,k;
         scanf("%d%d%d",&l,&r,&k);
         l++,r++;
         )-;
         ,len,root[l-],root[r],z));
         else printf("0\n");// 如果要查的数不在 a数组中直接输出0 k<min(an)
      }
   }
}

HDU--4417 Super Mario (主席树模版题)的更多相关文章

  1. HDU 4417 Super Mario 主席树

    分析:找一个区间里小于等于h的数量,然后这个题先离散化一下,很简单 然后我写这个题主要是熟悉一下主席树,其实这个题完全可以离线做,很简单 但是学了主席树以后,我发现,在线做,一样简单,而且不需要思考 ...

  2. HDU 4417 Super Mario 主席树查询区间小于某个值的个数

    #include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> ...

  3. HDU 4417 Super Mario(划分树)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. HDU 4417 Super Mario(划分树问题求不大于k的数有多少)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

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

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

  6. HDU 4417 Super Mario ( 离线树状数组 )

    把数值和查询放在一起从小到大排序,纪录每个数值的位置,当遇到数值时就更新到树状数组中,遇到查询就直接查询该区间和. #include <cstdio> #include <cstri ...

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

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

  8. HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  9. 主席树:HDU 4417 Super Mario

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. hdu 4417 Super Mario (主席树)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意: 给你段长为n的序列,有q个询问,每次询问区间[l.r]内有多少个数小于等于k 思路: 之前用 ...

随机推荐

  1. cmd远程连接oracle数据库

  2. VS code常用快捷方式—转载

    http://www.cnblogs.com/weihe-xunwu/p/6687000.html

  3. Spring拦截器(学习笔记)

    SpringMVC 中的Interceptor 拦截请求是通过HandlerInterceptor 来实现的 在SpringMVC 中定义一个Interceptor 非常简单,主要有两种方式 第一种方 ...

  4. netstat -na 查看有大量TIME_WAIT解决办法(修改内核参数)

    # netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c      16 CLOSING     130 ESTABLISHED     298 FIN_WA ...

  5. scss 转为 less

    tnpm install less-plugin-sass2less -g && sass2less **/*.scss {dir}/{name}.less && rm ...

  6. MyBatis Generator报错:Cannot instantiate object of type

    [ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate ( ...

  7. ES 6 系列 - 对于常用对象的拓展 api

    本篇中学习并记录可能会比较常用的 api ,详细请自行查找相关资料. 一.字符串的拓展 es 6 加强了对于 Unicode 的支持.javascript 允许采用 \uxxxxx 的方式表示一个字符 ...

  8. C# WebSocket模拟发送接收

    WebSocket服务端 C#示例代码 using System; using System.Collections.Generic; using System.Linq; using System. ...

  9. codeforces982F

    The Meeting Place Cannot Be Changed CodeForces - 982F Petr is a detective in Braginsk. Somebody stol ...

  10. raise missingsectionheadererror:file containe no section headers问题解决

    本人亲测,遇到这个问题,就换到管理员方式运行命令 因为太小白,所以这次重新装包的时候切换到D盘了,想着省一点儿C盘内存,结果,每次pip install安装的时候都是这个问题,中间还有什么反序列失败, ...