可怜的狗狗

思路:

  主席树第k大;

代码:

#include <bits/stdc++.h>
using namespace std;
#define maxn 300001
#define maxn_ maxn*30
int n,m,lc[maxn_],rc[maxn_],dis[maxn_],root[maxn];
int tot,ai[maxn],bi[maxn],size;
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
void build(int &now,int l,int r)
{
now=++tot;
if(l==r)return;
int mid=l+r>>;
build(lc[now],l,mid);
build(rc[now],mid+,r);
}
void add(int &now,int pre,int l,int r,int to)
{
now=++tot,dis[now]=dis[pre]+;
if(l==r) return;int mid=l+r>>;
if(to<=mid) add(lc[now],lc[pre],l,mid,to),rc[now]=rc[pre];
else add(rc[now],rc[pre],mid+,r,to),lc[now]=lc[pre];
}
int query(int now,int pre,int l,int r,int k)
{
if(l==r) return l;int mid=l+r>>;
int di=dis[lc[now]]-dis[lc[pre]];
if(k<=di) return query(lc[now],lc[pre],l,mid,k);
else return query(rc[now],rc[pre],mid+,r,k-di);
}
int main()
{
in(n),in(m);
for(int i=;i<=n;i++) in(ai[i]),bi[i]=ai[i];
sort(bi+,bi+n+),size=unique(bi+,bi+n+)-bi-;
build(root[],,size);
for(int i=;i<=n;i++)
{
int to=lower_bound(bi+,bi+size+,ai[i])-bi;
add(root[i],root[i-],,size,to);
}
int l,r,k;
while(m--)
{
in(l),in(r),in(k);
printf("%d\n",bi[query(root[r],root[l-],,size,k)]);
}
return ;
}

AC日记——可怜的狗狗 洛谷 P1533的更多相关文章

  1. AC日记——[SDOI2015]星际战争 洛谷 P3324

    题目描述 3333年,在银河系的某星球上,X军团和Y军团正在激烈地作战. 在战斗的某一阶段,Y军团一共派遣了N个巨型机器人进攻X军团的阵地,其中第i个巨型机器人的装甲值为Ai.当一个巨型机器人的装甲值 ...

  2. AC日记——联合权值 洛谷 P1351

    题目描述 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v 点的最短距离. ...

  3. AC日记——I Hate It 洛谷 P1531

    题目背景 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 题目描述 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的 ...

  4. AC日记——神奇的幻方 洛谷 P2615(大模拟)

    题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...

  5. AC日记——[CQOI2009]DANCE跳舞 洛谷 P3153

    [CQOI2009]DANCE跳舞 思路: 二分+最大流: 代码: #include <cstdio> #include <cstring> #include <iost ...

  6. AC日记——松江1843路 洛谷七月月赛

    松江1843路 思路: 三分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #define ...

  7. AC日记——严酷的训练 洛谷 P2430

    严酷的训练 思路: 背包: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 5005 int n,m,bi[m ...

  8. AC日记——[SDOI2010]大陆争霸 洛谷 P3690

    [SDOI2010]大陆争霸 思路: dijkstra模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn ...

  9. AC日记——小魔女帕琪 洛谷 P3802

    小魔女帕琪 思路: 概率公式计算: 代码: #include <bits/stdc++.h> using namespace std; ],sig; int main() { ;i< ...

随机推荐

  1. 删除空格-sed

    如下,我需要提取出‘wan’这个字符串.可以发现在‘wan’的前后是有空格,需要将其删除. # lxc list # lxc list | grep lxdbr0 | awk -F "|&q ...

  2. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)A 水 B 二分 C并查集

    A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  3. Codeforces Round #311 (Div. 2)B. Pasha and Tea二分

    B. Pasha and Tea time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. leetcode 刷题日志 2018-3-28

    树: 404. 左叶子之和 求所有左叶子结点之和 . 递归法 分析:递归法遍历结点,找左叶子结点 空指针判断 有左子节点?是叶子结点?是的话更新value的值 int sumOfLeftLeaves( ...

  5. HDU 5643 King's Game | 约瑟夫环变形

    经典约瑟夫环 }; ; i<=n; i++) { f[i] = (f[i-] + k) % i; } 变形:k是变化的 #include <iostream> #include &l ...

  6. iOS排序

    NSArray *originalArray = @[@,@,@,@,@]; //block比较方法,数组中可以是NSInteger,NSString(需要转换) NSComparator finde ...

  7. bzoj 4552: [Tjoi2016&Heoi2016]排序——二分+线段树

    Description 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题 ,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这 ...

  8. 【TYVJ】P1038 忠诚

    [算法]线段树 #include<cstdio> #include<algorithm> using namespace std; ]; ,inf=0x3f3f3f3f; in ...

  9. quartz的简介

    1. 介绍  Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源的任务调度框架,是完全由java开发的一个开源的任务日程管理系统,“任务进度管理器”就是一个在预 ...

  10. hydra 密码破解工具详解

    一.简介 hydra是著名黑客组织thc的一款开源的暴力密码破解工具,可以在线破解多种密码.官 网:http://www.thc.org/thc-hydra,可支持AFP, Cisco AAA, Ci ...