题干:

You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105).

For each i \in [1,n]i∈[1,n], construct a sequence s_isi​ by the following rules:

  1. s_i[1]=isi​[1]=i;
  2. The length of s_isi​ is nn, and for each j \in [2, n]j∈[2,n], s_i[j] \le s_i[j-1]si​[j]≤si​[j−1];
  3. First, we must choose all the possible elements of s_isi​ from permutation aa. If the index of s_i[j]si​[j] in permutation aa is pos[j]pos[j], for each j \ge 2j≥2, |pos[j]-pos[j-1]|\le k∣pos[j]−pos[j−1]∣≤k (1 \le k \le 10^51≤k≤105). And for each s_isi​, every element of s_isi​ must occur in aa at most once.
  4. After we choose all possible elements for s_isi​, if the length of s_isi​ is smaller than nn, the value of every undetermined element of s_isi​ is 00;
  5. For each s_isi​, we must make its weight high enough.

Consider two sequences C = [c_1, c_2, ... c_n]C=[c1​,c2​,...cn​] and D=[d_1, d_2, ..., d_n]D=[d1​,d2​,...,dn​], we say the weight of CC is higher thanthat of DD if and only if there exists an integer kk such that 1 \le k \le n1≤k≤n, c_i=d_ici​=di​ for all 1 \le i < k1≤i<k, and c_k > d_kck​>dk​.

If for each i \in [1,n]i∈[1,n], c_i=d_ici​=di​, the weight of CC is equal to the weight of DD.

For each i \in [1,n]i∈[1,n], print the number of non-zero elements of s_isi​ separated by a space.

It's guaranteed that there is only one possible answer.

Input

There are multiple test cases.

The first line contains one integer T(1 \le T \le 20)T(1≤T≤20), denoting the number of test cases.

Each test case contains two lines, the first line contains two integers nn and kk (1 \le n,k \le 10^51≤n,k≤105), the second line contains nn distinct integers a_1, a_2, ..., a_na1​,a2​,...,an​ (1 \le a_i \le n1≤ai​≤n) separated by a space, which is the permutation aa.

Output

For each test case, print one line consists of nn integers |s_1|, |s_2|, ..., |s_n|∣s1​∣,∣s2​∣,...,∣sn​∣ separated by a space.

|s_i|∣si​∣ is the number of non-zero elements of sequence s_isi​.

There is no space at the end of the line.

样例输入复制

2
3 1
3 2 1
7 2
3 1 4 6 2 5 7

样例输出复制

1 2 3
1 1 2 3 2 3 3

题目大意:

给你一个1~n的排列

解题报告:

首先贪心的思想,每个元素的下一个元素一定是与他距离不超过 k 的所有元素中,权值最大的元素,所以每个元素的下一个元素是固定的,我们可以通过滑动窗口 + set 上二分的预处理计算出每个元素的下一个元素,之后通过一个记忆化搜索即可 O(n) 求出每一个贪心序列的长度。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int a[MAX];
int n,q;
set<int> ss;
int db[MAX];//cun index
int ans[MAX];
int k;
int main()
{int T;cin>>T;while(T--) {scanf("%d%d",&n,&k);ss.clear();for(int i = 1; i<=n; i++) scanf("%d",a+i);int l=1-k,r=1+k;for(int i = 1; i<=r; i++) ss.insert(a[i]);for(int i = 1; i<=n; i++) { l = i-k,r = i+k;auto it = ss.lower_bound(a[i]);if(it != ss.begin()) {it--;db[a[i]] = (*it);}else db[a[i]] = 0;           if(l >= 1) {auto it = ss.lower_bound(a[l]);ss.erase(it);}if(r+1<=n) {ss.insert(a[r+1]);}}for(int i = 1; i<=n; i++) ans[i] = ans[db[i]]+1;for(int i = 1; i<=n; i++) {printf("%d%c",ans[i],i == n ? '\n' :' ');}}return 0 ;
}

【2019icpc南京站网络赛 - F】Greedy Sequence(思维,贪心构造,STLset)相关推荐

  1. 2019 ICPC 南京网络赛 F Greedy Sequence

    You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each i \in [1,n]i∈[1,n], c ...

  2. 【2019icpc南京站网络赛 - H】Holy Grail(最短路,spfa判负环)

    题干: As the current heir of a wizarding family with a long history,unfortunately, you find yourself f ...

  3. hdu5489(2015合肥网络赛F题)

    转载自:http://blog.csdn.net/lwt36/article/details/48774103 题意: 给出一个数列,在其中删除连续的L个数字,使得剩余的数字LIS最大,输出此LIS. ...

  4. hdu5455(2015沈阳网络赛F题)

    题意: 给出一个串,问用题中定义的那些串来组成这个串最少要用多少个. 思路: 没啥说的,注意一下输入的串中可能出现除了c和f的字母. 代码: #include<cstdio> #inclu ...

  5. hdu5442(2015长春网络赛F题)

    题意: 给出一个字符串,只由'a'~'z'组成,字符串是一个首尾相接的串.我们要找到一个起点,顺时针或者逆时针的读这个串,找到字典序最大的读法,如果有多种,输出起点坐标小的那个,如果起点坐标一样,输出 ...

  6. HDU 4812 D Tree (点分治) (2013ACM/ICPC亚洲区南京站现场赛)

    HDU 4812 D Tree 思路 点对距离相等并且要求输出字典序最小的点对,距离相等不就是点分治裸题了嘛, 照着这个思路出发我们只要记录下所有点对是满足要求的,然后再去找字典序最小的点对就行了, ...

  7. 2018ACM-ICPC南京赛区网络赛: J. Sum(积性函数前缀和)

    J. Sum A square-free integer is an integer which is indivisible by any square number except 11. For ...

  8. 2018ACM-ICPC 焦作站现场赛 F. Honeycomb(BFS求最短路,卡memset)

    F. Honeycomb 从前不信命,从这道题开始,我信了. 我就是没有拿牌子的命.这道题或者说这个memset,击碎了我所有对ACM的美好记忆. #include<bits/stdc++.h& ...

  9. 2017acm乌鲁木齐赛区网络赛F题tarjan缩点

    poj1236是问把一棵树变成强联通分量,于是答案就是rudu为0的和出度为0的最大值,因为假设入度为0的多一些,先每个出度为0的连接一个入度为0的,那么还剩一些入度为0的,这时候入度为0的随意连接一 ...

最新文章

  1. 图论 ---- E. Bear and Forgotten Tree 2(判补图的联通性技巧 图遍历的优化 条件拆分)
  2. python培训就业班口碑排行榜-Python就业班培训多少钱?老男孩Python收费标准
  3. 分享5个可视化的正则表达式编辑工具
  4. linux 常见服务端口
  5. SpringMVC框架--学习笔记(上)
  6. 让智能家居产品操控更简单 快捷键来了
  7. [原]简述Field,Attribute,Property的区别
  8. python 读取邮件内容_Python 如何提取邮件内容
  9. linux 单用户模式 挂载u盘_(原创)Linux文件系统只读Read-only file system的快速解决方法...
  10. Andriod:serializer序列化器生成xml文件
  11. Mac查看占用端口进程
  12. 2018年迎春杯复赛入围名单(四年级)
  13. php网易云信im即时通讯和聊天室
  14. javascript 代码转换为 typescript 代码
  15. ButterKnife 懒人神器 使用步骤 备忘
  16. 地理信息三维可视化技术在城市规划中的应用
  17. Docker (四) 容器基本命令
  18. 如何查询计算机com口使用
  19. 华硕飞行堡垒8intel WiFi6 AX201 160mhz网络适配器报错问题解决日志
  20. hbs模块 mysql_让koa-hbs模块支持koa2

热门文章

  1. 开始-运行 下常用快捷命令
  2. c++ new一个结构体_「C/C++」构造类型及应用:数组、结构体、共用体、枚举类型...
  3. OpenCV函数cvFindContours
  4. uci数据集_数据分析找不到数据集?快来看这个盘点
  5. 可信计算 沈昌祥_沈昌祥院士:用主动免疫可信计算构筑车联网安全防线
  6. asp.net 安装element ui_不用上官网,自己部署一套Element官方最新文档
  7. java 代码重用需要注意的事项_程序员笔记|编写高性能的Java代码需要注意的4个问题...
  8. linux中shell编写数组排序,linux bash shell实现对数组快速排序(升序)
  9. linux vi使用手册,史上最全VIM使用手册
  10. Linux内核Crash分析