题意:

查找区间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. vue-cli3项目中引入jquery 以及如何引进bootstrap

    1.安装jquery npm install jquery --save 2.或则在package.json中指定版本号,然后运行npm install命令 "dependencies&qu ...

  2. [BJOI2015]树的同构 && 树哈希教程

    题目链接 有根树的哈希 离散数学中对树哈希的描述在这里.大家可以看看. 判断有根树是否同构,可以考虑将有根树编码.而编码过程中,要求保留树形态的特征,同时忽略子树顺序的不同.先来看一看这个方法: 不妨 ...

  3. 关于数据库表设计之区域表system_district:省市县街道四级地址表

    关于省市县的数据表的设计有两种方式: 一.将其设计成一张表 DROP TABLE IF EXISTS `system_district`; CREATE TABLE `system_district` ...

  4. 「前端」尚妆 UI 组件库工程实践(weex vue)

    本文来自尚妆前端团队南洋 发表于尚妆github博客,欢迎订阅! 前言 尚妆大前端团队使用 weex 进行三端统一开发有一段时间了,截止本文发表「达人店」APP大部分页面都已经用 weex 进行了重构 ...

  5. Mac Vmware NAT模式

    1.NAT模式原理 2.MAC上关于Vmware的配置 1)/Library/Preferences/VMware Fusion/networking MacBookPro:~ zhangxm$ vi ...

  6. weblogic性能调优

    1.设置java参数: a) 编辑Weblogic Server启动脚本文件: /user_projects/domains/Domain_jgbs/bin/startWebLogic.sh /use ...

  7. linux目录简介说明

  8. anroid学习笔记(1)

    大概是2个月前,报名了慕课的android就业班课程. 算是补全了当初博客分类的最初设计. 安卓和前端比较: 1,java在安卓开发中的作用,现在我的认识是和JavaScript在前端web开发中有很 ...

  9. 给JAVA的eclipse IDE 在线安装 SVN插件 / 给 eclipse 添加打开所在的文件夹功能

    http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA 首先,在这个网址找着最新在线安装链接 就是那个 Links for ...

  10. DOM解析和SAX解析对比

    原理: 一次性加载xml文档,不适合大容量的文件读取 原理: 加载一点,读取一点,处理一点.适合大容量文件的读取 DOM解析可以任意进行增删改成 SAX解析只能读取 DOM解析任意读取任何位置的数据, ...