2020牛客暑期多校训练营(第六场)——K K-Bag

2020牛客暑期多校训练营(第六场)——K K-Bag

题目描述

A sequence is called kk-bag, if and only if it is put in order by some (maybe one) permutations of 1 to k. For example, 1,2,3,2,1,3,3,2,1 is a valid 33-bag sequence.
Roundgod is not satisfied with k-bag, so she put forward part-k-bag, which is a contiguous subsequence of k-bag.
Wcy wants to know if the sequence of length nn is a part-k-bag sequence.

输入描述

The first line contains one integer T (1≤T≤20), denoting the number of test cases. Then T test cases follow.
The first line of each test case contains two integers n,k (1≤n≤5*105,1≤k≤109).
The second line of each test case contains nn integers indicate the sequence.
It is guaranteed that ∑n≤2⋅106, the values of the sequence are between 11 and 109.

输出描述

One line of each test case, if the sequence is a part-k-bag sequence, print “YES”, otherwise print “NO”.

样例输入

1
8 3
2 3 2 1 3 3 2 1

样例输出

YES

题意

当一个数列可以表示为若干个1到k的排列依次组成时,这个数列被称为k-bag。例如1,2,3,2,1,3,3,2,1是一个3-bag。
如果一个序列是一个k-bag的连续子串,则其称为part-k-bag。
求一个长度为n的序列是否是一个part-k-bag。
第一行包含一个整数T(1≤T≤20),表示测试用例的数量。
然后是T个样例。每个测试案例的第一行包含两个整数n,k(1≤n≤5⋅105,1≤k≤109)。
每个测试案例的第二行包含n个整数表示序列。保证∑n≤2⋅106,序列的值在1到109之间。
如果一个序列是部分k-bag序列,则打印“YES”,否则打印“NO”。

题解

在这里插入图片描述

AC代码

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int num[500005],val[500005],cnt[500005],lpos[5
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值