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], construct a sequence s_isi by the following rules:
- s_i[1]=isi[1]=i;
- 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];
- 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.
- 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;
- 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
这题是队友出的,这个题好像线段树能做,但是我们是暴力加贪心做的,前几遍是枚举的区间位置纯暴力,后来是枚举左右区间长度,对于每个元素的下一个元素都是唯一固定的。之后记忆化搜索就可以求出每个序列。
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define LL long long
#define MAXN 100100
int a[MAXN],pos[MAXN];
int s[MAXN],oo[MAXN];
int main()
{
int t;
scanf("%d",&t);
int n,k,l,r,maxx;
while(t--){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
scanf("%d",a+i);
pos[a[i]]=i;
s[i]=1;
}
s[0]=0;
for(int i=2;i<=n;i++){
int j=i-1;
while(j>0){
if(abs(pos[i]-pos[j])<=k){
s[i]+=s[j];
break;
}
j--;
}
}
for(int i=1;i<=n;i++){printf("%d",s[i]);if(i<n)printf(" ");}
printf("\n");
}
}
2019 ICPC 南京网络赛 F Greedy Sequence的更多相关文章
- 2019 ICPC南京网络赛 F题 Greedy Sequence(贪心+递推)
计蒜客题目链接:https://nanti.jisuanke.com/t/41303 题目:给你一个序列a,你可以从其中选取元素,构建n个串,每个串的长度为n,构造的si串要满足以下条件, 1. si ...
- 2019ICPC南京网络赛F Greedy Sequence
题意:对于1<=i<=n每次找到(pos[i]-k,pos[i]+k)内不大于i的最大那个数,ans[i]=ans[mx]+1,若ans[mx]未知则递归处理ans[mx] PS:这个题比 ...
- 2013 ACM/ICPC 南京网络赛F题
题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...
- 2019 ICPC 南京网络赛 H-Holy Grail
As the current heir of a wizarding family with a long history,unfortunately, you find yourself force ...
- 2019 ICPC 南昌网络赛
2019 ICPC 南昌网络赛 比赛时间:2019.9.8 比赛链接:The 2019 Asia Nanchang First Round Online Programming Contest 总结 ...
- 2019 ICPC上海网络赛 A 题 Lightning Routing I (动态维护树的直径)
题目: 给定一棵树, 带边权. 现在有2种操作: 1.修改第i条边的权值. 2.询问u到其他一个任意点的最大距离是多少. 题解: 树的直径可以通过两次 dfs() 的方法求得.换句话说,到任意点最远的 ...
- 2018 ICPC南京网络赛 Set(字典树 + 合并 + lazy更新)
题解:n个集合,你要进行m个操作.总共有3种操作.第一种,合并两个集合x和y.第二张,把特定的集合里面所有的数字加一.第三种,询问在某个集合里面,对于所有数字对2的k次方取模后,有多少个数字等于x. ...
- 2019年南京网络赛E题K Sum(莫比乌斯反演+杜教筛+欧拉降幂)
目录 题目链接 思路 代码 题目链接 传送门 思路 首先我们将原式化简: \[ \begin{aligned} &\sum\limits_{l_1=1}^{n}\sum\limits_{l_2 ...
- 2013 ACM/ICPC 长春网络赛F题
题意:两个人轮流说数字,第一个人可以说区间[1~k]中的一个,之后每次每人都可以说一个比前一个人所说数字大一点的数字,相邻两次数字只差在区间[1~k].谁先>=N,谁输.问最后是第一个人赢还是第 ...
随机推荐
- rest_framework-分页
分页 from django.shortcuts import render # Create your views here. from rest_framework import serializ ...
- (js描述的)数据结构[树结构之红黑树](13)
1.二叉送搜索树的缺点: 2.红黑树难度: 3.红黑树五大规则: 4.红黑树五大规则的作用: 5.红黑树二大变换: 1)变色 2)旋转 6.红黑树的插入五种变换情况: 先声明--------插入的数据 ...
- Pytest系列(16)- 分布式测试插件之pytest-xdist的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 平常我们功能测试用例非常多时 ...
- 百度AI开发平台简介
AIstudio https://aistudio.baidu.com/aistudio/index 关于AI Studio AI Studio是基于百度深度学习平台飞桨的一站式AI开发平台,提供在线 ...
- stand up meeting 1/8/2016 & weekend 1/9/2016~1/10/2016 && sprint2扫尾
part 组员 工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 跑通打印机功能,尝试与pdf读取部分结合 6 查漏补缺, ...
- 详解 List接口
本篇博文所讲解的这两个类,都是泛型类(关于泛型,本人在之前的博文中提到过),我们在学习C语言时,对于数据的存储,用的差不多都是数组和链表. 但是,在Java中,链表就相对地失去了它的存在价值,因为Ja ...
- Python数据预处理:使用Dask和Numba并行化加速
如果你善于使用Pandas变换数据.创建特征以及清洗数据等,那么你就能够轻松地使用Dask和Numba并行加速你的工作.单纯从速度上比较,Dask完胜Python,而Numba打败Dask,那么Num ...
- Asp.Net Core 3.1 学习3、Web Api 中基于JWT的token验证及Swagger使用
1.初始JWT 1.1.JWT原理 JWT(JSON Web Token)是目前最流行的跨域身份验证解决方案,他的优势就在于服务器不用存token便于分布式开发,给APP提供数据用于前后端分离的项目. ...
- Java 网络编程 -- 基于TCP 模拟多用户登录
Java TCP的基本操作参考前一篇:Java 网络编程 – 基于TCP实现文件上传 实现多用户操作之前先实现以下单用户操作,假设目前有一个用户: 账号:zs 密码:123 服务端: public c ...
- JavaScript--'data-'的用法(1)
HTML5为我们提供了一个强大的功能,前段也也能实现后台数据库的效果,例如data-xxx <a href="#myModal" data-industry_id=" ...