主席树,区间第$k$大。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int maxn=;
int a[maxn],b[maxn],root[maxn],n,m,sz;
struct Node {int l,r,sum;} s[maxn*]; int get(int x)
{
int L=,R=n,res;
while(L<=R)
{
int mid=(L+R)/;
if(b[mid]>x) R=mid-;
else if(b[mid]<x) L=mid+;
else res=mid,R=mid-;
}
return res;
} void update(int l,int r,int &x,int y,int p)
{
sz++; s[sz]=s[y]; s[sz].sum++; x=sz;
if(l==r) return;
int mid=(l+r)/;
if(p<=mid) update(l,mid,s[sz].l,s[y].l,p);
else update(mid+,r,s[sz].r,s[y].r,p);
} int quary(int l,int r,int x,int y,int p)
{
if(l==r) return l;
int mid=(l+r)/;
int tmp=s[s[y].l].sum-s[s[x].l].sum;
if(tmp>=p) return quary(l,mid,s[x].l,s[y].l,p);
else return quary(mid+,r,s[x].r,s[y].r,p-tmp);
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i];
sort(b+,b++n); for(int i=;i<=n;i++) a[i]=get(a[i]);
for(int i=;i<=n;i++) update(,n,root[i],root[i-],a[i]);
for(int i=;i<=m;i++)
{
int L,R,k; scanf("%d%d%d",&L,&R,&k);
printf("%d\n",b[quary(,n,root[L-],root[R],k)]);
}
return ;
}

POJ 2761 Feed the dogs的更多相关文章

  1. poj 2761 Feed the dogs (treap树)

    /************************************************************* 题目: Feed the dogs(poj 2761) 链接: http: ...

  2. POJ 2761 Feed the dogs(平衡树or划分树or主席树)

    Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs ...

  3. POJ 2761 Feed the dogs (主席树)(K-th 值)

                                                                Feed the dogs Time Limit: 6000MS   Memor ...

  4. POJ 题目2761 Feed the dogs(主席树||划分树)

    Feed the dogs Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 16860   Accepted: 5273 De ...

  5. 划分树---Feed the dogs

    POJ  2761 Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to fee ...

  6. 【POJ2761】【区间第k大】Feed the dogs(吐槽)

    Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs ...

  7. poj 2761 主席树的应用(查询区间第k小值)

    Feed the dogs Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 22084   Accepted: 7033 De ...

  8. [POJ2761] Feed the dogs (Treap)

    题目链接:http://poj.org/problem?id=2761 题目大意:给你n个数,m次查询,m次查询分别是a,b,k,查询下表从a到b的第k小元素是哪个.这m个区间不会互相包含. Trea ...

  9. 【poj2761】 Feed the dogs

    http://poj.org/problem?id=2761 (题目链接) 题意 求区间第K大. Solution 和poj2104一模一样. 主席树代码 // poj2761 #include< ...

随机推荐

  1. c++类的构造函数与析构函数

    为什么用构造函数与析构函数 构造函数: c++目标是让使用类对象就像使用标准类型一样,但是常规化的初始化句法不适用与类类型. ; //基本类型 struct thing { char *pn; int ...

  2. SQLite数据库操作 (原始操作)

    android提供了一个名为SQLiteDatabase的类,该类封装了一些操作数据库的API, 使用该类可以完成对数据进行添加(Create).查询(Retrieve).更新(Update)和删除( ...

  3. 理解对象模型图(Reading OMDS)

    理解对象模型图(Reading OMDS) 引言 这篇文章大部分内容是翻译的帮助资料里的东西.学习技术,英语是个好工具.一直把英语的地位看得和技术一样重,也会强迫自己看英语版的技术书籍(都是PDF版的 ...

  4. cocos2d(背景图片循环滚动)

    背景图片循环滚动 使用action 实现的: 主要有两个背景图片交替循环滚动:我选的两个背景图片的宽度都是1024的 ,所以定义了#define BGIMG_WIDTH 1024 代码如下: 在Hel ...

  5. IOS学习之路十八(通过 NSURLConnection 发送 HTTP 各种请求)

    你想通过 Http 协议向服务器发送一个 Get 的包装请求,并在这个请求中添加了一些请 求参数. 向远程服务器发送一个 GET 请求,然后解析返回的数据.通常一个 GET 请求是添加了 一些参数的, ...

  6. NodeJS系列-部署

    NodeJS系列-部署 NodeJS我就不介绍了,被标题吸引进来的人可以看这个链接,了解NodeJS.下来就开始关于NodeJS开发的指南. NodeJS可以部署的平台有Windows,Unix,iO ...

  7. WPF制作的小型笔记本

    WPF制作的小型笔记本-仿有道云笔记 楼主所在的公司不允许下载外部资源, 不允许私自安装应用程序, 平时记录东西都是用记事本,时间久了很难找到以前记的东西. 平时在家都用有道笔记, 因此就模仿着做了一 ...

  8. 写一个简单的Web框架

    在.Net中有两种常用的Web开发方式,一种是Asp.Net WebForm,另一种是Asp.Net MVC.我先简单的给大家介绍下这两种开发方式的特点,然后再应用自定义脚本映射,反射,json2te ...

  9. MSBuild是什么?

    MSBuild入门 MSBuild是什么? MSBuild全称(Microsoft Build Engine),是用来生成.NET程序的平台.您可能不知道它,但是如果您在使用VS做开发,那么一定时时刻 ...

  10. SSH使用技巧

    SSH使用技巧 SSH免输入密码 原理是依赖证书去认证,从而免除密码输入. 通过ssh-keygen生成一对公私钥,是否使用passphrase可以根据个人喜好.(其实使用证书就是为了方便而已,我是不 ...