B. Moamen and k-subarrays

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:
准确地说是一次:

  1. Split the array into exactly k non-empty subarrays such that each element belongs to exactly one subarray.
    1.将数组拆分为完全k个非空子数组,使每个元素恰好属于一个子数组。

  2. Reorder these subarrays arbitrary.
    2.任意重新排序这些子数组。

  3. 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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值