1592B - Hemose Shopping - CodeForces Solution


constructive algorithms dsu math sortings *1200

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <iostream>
#include<unordered_map>
#define x first
#define y second

#define  ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

using namespace std;

typedef  long  long LL ;
typedef  unsigned long  long ULL ;
typedef pair<int,int> PII ;
typedef pair<LL,int> PLI ;
const int N = 2e5+10,M = 1000 * 100000 + 10 ,mod = 1000000007,INF1 = 0x3f3f3f3f;
const LL INF2 = 1e17;


//能否通过交换两个距离大于等于 x 的数,使得数组可以按照非递减的顺序来排序。

int  n,x,a[N],b[N];

bool check()
{
    // x == n/2
    for(int i=n-x+1;i<=x;i ++ )
        if(a[i] != b[i]) return 0;
    return 1;
}
inline void solve() {
    cin>>n>>x;
    for(int i=1;i<= n;i ++ )cin>> a[i],b[i] =a[i];

    if(x *2  <=n)
    {
        cout <<"YES" << endl;return ;
    }

    sort(b+1,b+n+1);
    // 这里  x* 2 >= n  ==== x >= n/2
    if(!check()) cout << "NO" << endl;
    else cout << "YES" <<endl;

}
signed main()
{
	ios
    int T;cin>>T;
    while(T -- )
    {
        solve();

    }


    return 0;
}


Comments

Submit
0 Comments
More Questions

1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push