题意:

查找区间k的后继。

思路:

直接主席树。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e5+; int tot;
int root[N];//forest_root;
struct node
{
int l,r,sz;
}tr[N*];//Log(n) //=========================================
void Init()
{
tot=;
}
int Build(int l,int r)
{
int now=++tot;
tr[now].sz=;
int mid=(l+r)>>;
if(l<r)
{
tr[now].l=Build(l,mid);
tr[now].r=Build(mid+,r);
}
return now;
}
int update(int pre,int l,int r,int x)
{
int now=++tot;
tr[now].sz=tr[pre].sz+;
tr[now].l=tr[pre].l;
tr[now].r=tr[pre].r;
if(l<r)
{
int mid=(l+r)>>;
if(x>mid)
tr[now].r=update(tr[pre].r,mid+,r,x);
else
tr[now].l=update(tr[pre].l,l,mid,x);
}
return now;
}
int Query_min(int u,int v,int l,int r,int k)
{
if(tr[v].sz-tr[u].sz==)return ;
if(l==r)return l<k?l:;
int mid=(l+r)>>;
if(k<=mid+||tr[tr[v].r].sz-tr[tr[u].r].sz==)
return Query_min(tr[u].l,tr[v].l,l,mid,k);
int t=Query_min(tr[u].r,tr[v].r,mid+,r,k);
if(t)return t;
return Query_min(tr[u].l,tr[v].l,l,mid,k);
}
int Q(int u,int v,int l,int r,int k)
{
if(l==r)return tr[v].sz-tr[u].sz;
int mid=(l+r)>>;
if(k<=mid)
return Q(tr[u].l,tr[v].l,l,mid,k);
else
return Q(tr[u].r,tr[v].r,mid+,r,k);
}
void check(int u,int v,int n)
{
for(int i=;i<=n;++i)
pr("%d ",Q(u,v,,n,i));
pr("\n");
} int a[N];
int pos[N];
int ans[N];
int main()
{
int T;
sc("%d",&T);
while(T--)
{
int n,k;
sc("%d%d",&n,&k);
Init();
root[]=Build(,n);
for(int i=;i<=n;++i)
{
sc("%d",&a[i]);ans[i]=;pos[a[i]]=i;
root[i]=update(root[i-],,n,a[i]);
}
for(int i=;i<=n;++i)
{
int t1=-;
if(pos[i]!=)
{
// pr("%d %d\n",max(pos[i]-k-1,0),pos[i]-1);
// check(root[max(pos[i]-k-1,0)],root[pos[i]-1],n);
int tt=Query_min(root[max(pos[i]-k-,)],root[pos[i]-],,n,i);
ans[i]=ans[tt]+;
t1=tt;
}
if(pos[i]!=n)
{
// pr("%d %d\n",pos[i],min(pos[i]+k,n));
// check(root[pos[i]],root[min(pos[i]+k,n)],n);
int tt=Query_min(root[pos[i]],root[min(pos[i]+k,n)],,n,i);
if(tt>t1)
ans[i]=ans[tt]+;
}
pr("%d%c",ans[i],i==n?'\n':' ');
}
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

F. Greedy Sequence(主席树区间k的后继)(The Preliminary Contest for ICPC Asia Nanjing 2019)的更多相关文章

  1. The Preliminary Contest for ICPC Asia Nanjing 2019( B H F)

    B. super_log 题意:研究一下就是求幂塔函数 %m的值. 思路:扩展欧拉降幂. AC代码: #include<bits/stdc++.h> using namespace std ...

  2. 树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019

    题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_wit ...

  3. The Preliminary Contest for ICPC Asia Nanjing 2019 A The beautiful values of the palace(树状数组+思维)

    Here is a square matrix of n * nn∗n, each lattice has its value (nn must be odd), and the center val ...

  4. 计蒜客 38229.Distance on the tree-1.树链剖分(边权)+可持久化线段树(区间小于等于k的数的个数)+离散化+离线处理 or 2.树上第k大(主席树)+二分+离散化+在线查询 (The Preliminary Contest for ICPC China Nanchang National Invitational 南昌邀请赛网络赛)

    Distance on the tree DSM(Data Structure Master) once learned about tree when he was preparing for NO ...

  5. 计蒜客 41387.XKC's basketball team-线段树(区间查找大于等于x的最靠右的位置) (The Preliminary Contest for ICPC Asia Xuzhou 2019 E.) 2019年徐州网络赛

    XKC's basketball team XKC , the captain of the basketball team , is directing a train of nn team mem ...

  6. The Preliminary Contest for ICPC Asia Shanghai 2019 F. Rhyme scheme(dp)

     题意:给你一个n和k 要你找到长度为n 字典序第k小的字符串 定义一个字符串合法:第i的字符的范围只能是前i-1个字符中的最大值+1 思路:我们dp[n][i][j]表示长度为n 在第i位 最大值为 ...

  7. The Preliminary Contest for ICPC Asia Shenyang 2019 F. Honk's pool

    题目链接:https://nanti.jisuanke.com/t/41406 思路:如果k的天数足够大,那么所有水池一定会趋于两种情况: ① 所有水池都是一样的水位,即平均水位 ② 最高水位的水池和 ...

  8. 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)

    query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...

  9. The Preliminary Contest for ICPC Asia Xuzhou 2019 G. Colorful String 回文树

    签到提: 题意:求出每一个回文串的贡献 (贡献的计算就是回文串不同字符的个数) 题解: 用回文树直接暴力即可 回文树开一个数组cost[ ][26] 和val[ ] 数组: val[i]表示回文树上节 ...

随机推荐

  1. delphi请求http接口中文乱码问题

    请求http接口的时候参数值是中文乱码: http接口一般都是由java,php以及C#开发而成的,乱码的原因也是由于编码的问题,一般传递数据的都是utf8,然后传递的时候都会urlEcode 那么d ...

  2. 创建虚拟机,安装操作系统,xshell6远程链接

    一.创建虚拟机 1. 首先安装vmware,注意在安装中,下面的两项不要勾选,一路下一步 2.完成安装打开之后,创建新的虚拟机 3.虚拟机创建完成,需要改配置 4.然后设置网段 5.查看服务,在运行状 ...

  3. JavaWeb_(Struts2框架)使用Struts框架实现用户的登陆

    JavaWeb_(Struts2框架)使用Servlet实现用户的登陆 传送门 JavaWeb_(Struts2框架)Servlet与Struts区别 传送门 MySQL数据库中存在Gary用户,密码 ...

  4. [POJ1151][HDU1542]Atlantis(线段树,扫描线)

    英文题面,我就只放个传送门了. Solution  题意是算矩形面积并,这是扫描线算法能解决的经典问题. 算法的大致思想是,把每一个矩形拆成上边和下边(以下称作扫描线),每条扫描线有四个参数l,r,h ...

  5. 如何使用getattr运行单个函数

    import sys def foo(): print("哈哈想不到吧") if __name__ == '__main__': getattr(sys.modules[__nam ...

  6. Linux 常用命令之df du

    1.du 命令:显示每个文件或目录的磁盘使用空间 1) du -h --max-depth [root@ip101 app]# pwd /opt/app [root@ip101 app]# du -h ...

  7. 升级日志sdfsdfsdfsdfsdfdsf

    升级日志sdfsdfsdfsdfsdfdsf 升级日志小书匠 版本号 新功能 修改

  8. mongodb将mysql数据导入

    1.首先将数据从mysql数据库导出为xls文件 SELECT * FROM user INTO OUTFILE "F:\1.xls" 2.notepad++打开,用utf8编码保 ...

  9. 小D课堂 - 零基础入门SpringBoot2.X到实战_第14节 高级篇幅之SpringBoot多环境配置_59、SpringBoot多环境配置介绍和项目实战

    笔记 1.SpringBoot多环境配置介绍和项目实战(核心知识)     简介:SpringBoot介绍多环境配置和使用场景 1.不同环境使用不同配置         例如数据库配置,在开发的时候, ...

  10. 工程变更(ENGINEERING CHANGE)

    工程变更(ENGINEERING CHANGE)是企业活动重要的管制项目之一,依照实施的时间.目的不同,其管制细分如下:  ECN (ENGINEERING CHANGE NOTICE)工程变更通知: ...