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,谁输.问最后是第一个人赢还是第 ...
随机推荐
- PHP如何配置session存储在redis
当网站用户量增多的时候,正常的session存取就会出现有点慢的问题,如果提高速度呢. 我们可以使用redis去保存session的会话信息. PHP的会话默认是以文件的形式存在的,可以配置到NoSQ ...
- Flask 入门(四)
url反转 当我学习到url反转的时候,看了一个人写的例子,如下: from flask import Flask,url_for app = Flask(__name__) @app.route ...
- Java 数据类型转换的骚操作和神奇现象
问:银行用什么数据类型来表示余额?float还是double? 都不是!!下面说明为什么都不可以呢? public static void main(String[] args) { //浮点数他都是 ...
- E - Dividing Chocolate ATcoder
题目大意:切割图形,给你一个非0即1的矩阵,将它切割成多个长方形,使每个小长方形中1的个数不得多于k个,切割的规则,要么切一整行,要么是一整列. 题解: 二进制枚举. 注意行数最大才是10.用二进制枚 ...
- 并发工具——CyclicBarrier
本博客系列是学习并发编程过程中的记录总结.由于文章比较多,写的时间也比较散,所以我整理了个目录贴(传送门),方便查阅. 并发编程系列博客传送门 CyclicBarrier简介 CyclicBarrie ...
- [PHP] 生成二维码(两种方法)
方法一:(调用google二维码接口,本人测试网不好,不好用!) <?php //1.封装生成二维码图片的函数(方法) /** *利用google api生成二维码图片 * $content:二 ...
- django-admin和manage.py用法
官网文档地址:django-admin和manage.py 金句: 所有的天赋,都来自于你对你喜欢的某种事物的模仿与学习,否则你就不会有这种天赋. 开篇话: 我们在Django开发过程中,命令行执行最 ...
- Linux-LAMP虚拟主机配置
1.配置用户认证 <Directory /data/discuz/passwd> AllowOverride AuthConfig AuthName "自定义的" Au ...
- [nodejs] 同步/异步创建多层目录
背景 有时项目里需要同时创建多层目录的功能,但低版本的nodejs并没有提供快捷的api 尽管在v10.12.0版本 mkdir() 第二个参数支持recursive 参数,为true时能递归创建,但 ...
- TensorFlow命令行参数FLAGS使用
import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' import tensorflow as tf #tensorboard --logdir=&qu ...