B. Moamen and k-subarrays
B.莫阿门和k-子阵
time limit per test: 2 seconds 每次测试的时间限制:2秒
memory limit per test: 256 megabytes 每次测试的内存限制:256兆字节
input: standard input 输入:标准输入
output: standard output 产出:标准产出
Moamen has an array of n distinct integers. He wants to sort that array in non-decreasing order by doing the fllwing operations in order 莫阿门有一个n个不同整数的数组。他希望通过按顺序执行fllwing操作,按非递减顺序对数组进行排序。
exactly once: 准确地说是一次:
-
Split the array into exactly k non-empty subarrays such that each element belongs to exactly one subarray. 1.将数组拆分为完全k个非空子数组,使每个元素恰好属于一个子数组。 -
Reorder these subarrays arbitrary. 2.任意重新排序这些子数组。 -
Merge the subarrays in their new order. 3.将子数组按新顺序合并。
A sequence a is a subarray of a sequence b if a can be obtained from b by deletion of several (possibly, zero or all) elements from the 序列a是序列b的子数组,如果可以从b中删除几个(可能是零或全部)元素来获得a。
beginning and several (possibly, zero or all) elements from the end. 开始和从末尾开始的几个(可能是零或全部)元素。
Can you tell Moamen if there is a way to sort the array in non-decreasing order using the operations written above? 你能告诉莫阿门,如果有一种方法来排序数组的非递减顺序使用上面写的操作?
Input 输入
The first line contains a single integert(1 < t < 103)- the number of test cases. The description of the test cases fllws. 第一行包含一个整数(1<t<103)–测试用例的数量。测试用例的描述。
The first line of each test case contains two integers nandk(1≤k≤n≤105). 每个测试用例的第一行包含两个整数nandk(1≤k≤n≤105)。
The second line contains n integers a1, a…,an(0≤|a|≤10"). It is guaranteed that all numbers are distinct. 第二行包含n个整数A1,a.,a,≤,≤10“,保证所有数字都是不同的。
It is guaranteed that the sum of n over all test cases does not exceed 3.105. 保证所有测试用例上n的和不超过3.105。
模拟 看有多少组符合顺序即可
int a[100007],b[100007];
map<ll ,ll>book;
int main()
{
int t;
cin >> t;
while (t--)
{
ll n,m;
ll sum=0;
cin>>n>>m;
for (int i = 0; i < n; ++i) {
cin>>a[i];
b[i]=a[i];
}
sort(b,b+n);
for (int i = 0; i < n-1; ++i) {
book[b[i]]=b[i+1];
}
book[b[n-1]]=-1e10;
for (int i = 0; i < n; ++i) {
sum++;
while(a[i+1]==book[a[i]])
{
++i;
}
}
//cout<<sum<<endl;///
if(sum<=m)
cout<<"Yes"<<endl;
else
cout<<"No\n";
}
return 0;
}
|