Problem:
Problem E: Cyclic Shift Sort
Problem
長さ $N$ の順列 $P = \{ P_1, P_2, \ldots, P_N \} $ と整数 $K$ が与えられる。
以下の操作を $0$ 回以上任意の回数繰り返すことで、順列 $P$ を単調増加にすることができるかどうか判定せよ。
整数 $x \ (0 \le x \le N-K)$ を選ぶ。 $ P_{x+1}, \ldots, P_{x+K} $ を巡回右シフトする
ただし、部分列 $U=U_1, \ldots, U_M$ の巡回右シフトとは、 $U=U_1, \ldots, U_M$ を $U=U_M, U_1, \ldots, U_{M-1}$ に変更することを意味する。
Input
入力は以下の形式で与えられる。
$N$ $K$
$P_1$ $\ldots$ $P_N$
1行目に順列の長さ $N$ 、整数 $K$ が空白区切りで与えられる。
2行目に順列 $P$ の要素が空白区切りで与えられる。
Constraints
入力は以下の条件を満たす。
$2 \leq K \leq N \leq 10^5 $
$ 1 \leq P_i \leq N \ (1 \leq i \leq N) $
$ P_i \neq P_j \ (i \neq j) $
入力はすべて整数
Output
$P$ を単調増加にすることができるなら"Yes"を、できないのであれば"No"を $1$ 行に出力せよ。
Sample Input 1
3 3
2 3 1
Sample Output 1
Yes
$ x = 0 $ として操作を $1$ 回行うと、 $P$ を単調増加にすることができる。
Sample Input 2
3 2
1 2 3
Sample Output 2
Yes
$P$ が初めから単調増加である場合もある。
Sample Input 3
3 3
3 2 1
Sample Output 3
No
どのように操作を行なったとしても、 $P$ を単調増加にすることはできない。

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <fstream>
class Bit {
	std::vector<int> vec;
public:
	Bit(const int size) : vec(size, 0) {};
	int operator[](int position) const {
		int result = 0;
		while (position >= 0) {
			result += vec[position];
			position -= ~position & (position + 1);
		}
		return result;
	}
	void increment(int position) {
		while (position < vec.size()) {
			vec[position]++;
			position += ~position & (position + 1);
		}
	}
};
int main() {
	int n, k; std::cin >> n >> k;
	std::vector<int> permutation(n); for (auto& p : permutation) std::cin >> p;
	if (n == k) {
		bool can_sort = true;
		for (auto i = 1; i < n; ++i) {
			if (permutation[i - 1] > permutation[i]) {
				if (can_sort) {
					can_sort = false;
				}
				else {
					std::cout << "No\n";
					return 0;
				}
			}
		}
		std::cout << "Yes\n";
	}
	else if (k % 2 == 0) {
		std::cout << "Yes\n";
	}
	else {
		Bit bit(n);
		long long int swap_count = 0;
		for (auto i = 0; i < n; ++i) {
			const auto p = permutation[i];
			swap_count += i - bit[p - 1];
			bit.increment(p - 1);
		}
		if (swap_count % 2 == 0) {
			std::cout << "Yes\n";
		}
		else {
			std::cout << "No\n";
		}
	}
}
accuracy: 1
time_ms: 20
memory_kb: 3608
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T>
struct BIT{
  Int n;
  vector<T> bit;
  //1-indexed
  BIT():n(-1){}
  BIT(Int n_,T d):n(n_),bit(n_+1,d){}

  T sum(Int i){
    T s=bit[0];
    for(Int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  void add(Int i,T a){
    if(i==0) return;
    for(Int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }
};


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  vector<Int> ps(n);
  for(Int i=0;i<n;i++) cin>>ps[i];

  if(n==k){
    vector<Int> vs;
    for(Int p:ps) vs.emplace_back(p);
    for(Int p:ps) vs.emplace_back(p);

    for(Int i=0;i<n;i++){
      if(vs[i]!=1) continue;
      Int flg=1;
      for(Int j=0;j<n;j++)
        flg&=vs[i+j]==j+1;
      cout<<(flg?"Yes":"No")<<endl;
      break;
    }
    return 0;
  }

  if(k%2==0) drop("Yes");

  BIT<Int> bit(n+10,0);
  Int sum=0;
  for(Int i=0;i<n;i++){
    sum+=i-bit.sum(ps[i]);
    sum%=2;
    bit.add(ps[i],1);
  }
  cout<<(sum?"No":"Yes")<<endl;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5644
final_rank: 14

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

ll inverse(int* A, int N) {
	ll ans = 0;
	ll a[N + 1000] = {};
	for (int i = 0; i < N; ++i) {
		for (int j = A[i]; j; j -= (j & (-j))) ans -= a[j]; ans += i;
		for (int j = A[i]; j <= N; j += (j & (-j))) a[j]++;
	}
	return ans;
}

signed main() {
	int n, k;
	cin >> n >> k;

	int p[n];
	for (int i = 0; i < n; ++i) {
		int pi; cin >> pi;
		p[i] = pi;
	}

	bool is_sorted = true;
	for (int i = 0; i < n; ++i)
		is_sorted = is_sorted && (p[i] == i + 1);
	if (is_sorted){
		cout << "Yes" << endl;
		exit(0);
	}

	if (n == k){
		bool ok = true;
		for (int i = 0; i < n; ++i){
			if (p[(i + 1) % n] != (p[i] != n ? (p[i] + 1) : 1))
				ok = false;
		}
		if (ok){
			cout << "Yes" << endl;
			exit(0);
		}
		else{
			cout << "No" << endl;
			exit(0);
		}
	}

	ll inv = inverse(p, n);

	if (k % 2 == 1 && inv % 2 == 1) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4272
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n, 0);
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main() {
    int N, K, P[100000];
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> P[i];

    bool ok = true;
    if(K == N){
        for(int i=0; i<N; i++) if((N+P[(i+1)%N]-P[i])%N != 1) ok = false;
    }else{
        int64_t s = 0;
        BIT<int> bit(N+1);
        for(int i=0; i<N; i++){
            s += bit.sum_between(P[i], N);
            bit.plus(P[i], 1);
        }
        ok = !(K%2) || !(s%2);
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3564
final_rank: 5

code_snippet: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,K;
vector<int> P;

class BIT{//1-indexed
public:

  vector<ll> bit;
  BIT(){}
  BIT(int size){
    bit.resize(size,0);
  }

  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&(-i);
    }
    return s;
  }

  void add(int i,ll x){//i!=0
    while(i<bit.size()){
      bit[i]+=x;
      i+=i&(-i);
    }
  }
};


int main(){
  cin>>N>>K;
  P.resize(N);
  rep(i,N) cin>>P[i];

  if(K==N){
    for(int i=0;i+1<N;i++){
      if(P[i]+1==P[i+1]||P[i]==N&&P[i+1]==1);
      else {
        cout<<"No"<<endl;
        return 0;
      }
    }
    cout<<"Yes"<<endl;
    return 0;
  }

  BIT bit(N+1);
  ll ans=0;
  for(int i=0;i<N;i++){
    ans+=i-bit.sum(P[i]);
    bit.add(P[i],1);
  }

  if(K%2==0||ans%2==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3888
final_rank: 9

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
template <typename Abelian>
struct BIT {
  BIT(int n, const Abelian &UNITY = 0) : n(n), UNITY(UNITY), dat(n, UNITY) {}

  void add(int idx, const Abelian &value) {
    while (idx < n) {
      dat[idx] += value;
      idx |= idx + 1;
    }
  }

  Abelian sum(int idx) {
    Abelian res = UNITY;
    while (idx >= 0) {
      res += dat[idx];
      idx = (idx & (idx + 1)) - 1;
    }
    return res;
  }

  Abelian sum(int left, int right) { return sum(right) - sum(left - 1); }

  Abelian operator[](const int idx) { return sum(idx, idx); }

  int lower_bound(Abelian value) {
    if (value <= UNITY) return 0;
    int res = 0, exponent = 1;
    while (exponent <= n) exponent <<= 1;
    for (int mask = exponent >> 1; mask > 0; mask >>= 1) {
      if (res + mask - 1 < n && dat[res + mask - 1] < value) {
        value -= dat[res + mask - 1];
        res += mask;
      }
    }
    return res;
  }

private:
  int n;
  const Abelian UNITY;
  vector<Abelian> dat;
};

template <typename T>
long long inversion_number(const vector<T> &a) {
  int n = a.size();
  vector<T> cp(a);
  sort(ALL(cp));
  cp.erase(unique(ALL(cp)), cp.end());
  BIT<int> bit(cp.size());
  long long res = 0;
  REP(i, n) {
    int idx = lower_bound(ALL(cp), a[i]) - cp.begin();
    res += i - bit.sum(idx);
    bit.add(idx, 1);
  }
  return res;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  vector<int> p(n); REP(i, n) cin >> p[i];
  if (n == k) {
    int idx = find(ALL(p), 1) - p.begin();
    REP(i, n) {
      if (p[(idx + i) % n] != 1 + i) {
        cout << "No\n";
        return 0;
      }
    }
    cout << "Yes\n";
    return 0;
  }
  if (k % 2 == 0) {
    cout << "Yes\n";
    return 0;
  }
  cout << (inversion_number(p) % 2 == 0 ? "Yes\n" : "No\n");
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4208
final_rank: 1

code_snippet: #include <iostream>
#include <vector>

using Int = long long int;
using std::vector;

// 加算と総和
struct SegmentTree {
    int length;
    vector<int> dat;

    int query(int ql, int qr, int nidx, int nl, int nr) {
        if (nr <= ql || qr <= nl) return 0;
        if (ql <= nl && nr <= qr) return dat[nidx];
        int vl = query(ql, qr, nidx * 2, nl, (nl + nr) / 2);
        int vr = query(ql, qr, nidx * 2 + 1, (nl + nr) / 2, nr);
        return vl + vr;
    }

    SegmentTree(int n) : length(1) {
        while (length < n) length <<= 1;
        dat.assign(length * 2, 0);
    }

    // half-open interval [ql, qr)
    int query(int ql, int qr) { return query(ql, qr, 1, 0, length); }

    void update(int idx, int e) {
        int nidx = idx + length;
        dat[nidx] += e;
        while (nidx > 0) {
            nidx >>= 1;
            dat[nidx] = dat[nidx * 2] + dat[nidx * 2 + 1];
        }
    }
};

int main() {
    int n, k;
    std::cin >> n >> k;

    vector<int> p(n);
    for (auto& x : p) {
        std::cin >> x;
        --x;
    }

    if (k == n) {
        int i;
        for (i = 0; p[i] != 0; ++i) {}
        for (int j = 0; j < n; ++j) {
            if (p[(i + j) % n] != j) {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    } else if (k % 2 == 1) {
        Int rev = 0;
        SegmentTree seg(n);
        for (auto x : p) {
            rev += seg.query(x + 1, n);
            seg.update(x, 1);
        }
        if (rev % 2 == 1) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4092
final_rank: 16

code_snippet: //#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

namespace n91 {

  using i8 = std::int_fast8_t;
  using i32 = std::int_fast32_t;
  using i64 = std::int_fast64_t;
  using u8 = std::uint_fast8_t;
  using u32 = std::uint_fast32_t;
  using u64 = std::uint_fast64_t;
  using isize = std::ptrdiff_t;
  using usize = std::size_t;

  constexpr usize operator"" _z(unsigned long long x) noexcept {
    return static_cast<usize>(x);
  }

  template <class T> class integral_iterator {
  public:
    using difference_type = T;
    using value_type = T;
    using pointer = const value_type*;
    using reference = value_type;
    using iterator_category = std::random_access_iterator_tag;

  private:
    using self_type = integral_iterator<value_type>;
    value_type i;

  public:
    constexpr integral_iterator() noexcept : i() {}
    explicit constexpr integral_iterator(const value_type i) noexcept : i(i) {}
    constexpr self_type operator++(int) noexcept { return self_type(i++); }
    constexpr self_type operator--(int) noexcept { return self_type(i--); }
    constexpr self_type operator[](const difference_type rhs) const noexcept {
      return self_type(i + rhs);
    }
    constexpr self_type& operator++() noexcept {
      ++i;
      return *this;
    }
    constexpr self_type& operator--() noexcept {
      --i;
      return *this;
    }
    constexpr reference operator*() const noexcept { return i; }
    constexpr self_type operator+(const difference_type rhs) const noexcept {
      return self_type(i + rhs);
    }
    constexpr self_type operator-(const difference_type rhs) const noexcept {
      return self_type(i - rhs);
    }
    constexpr difference_type operator-(const self_type rhs) const noexcept {
      return i - rhs.i;
    }
    constexpr bool operator<(const self_type rhs) const noexcept {
      return i < rhs.i;
    }
    constexpr bool operator<=(const self_type rhs) const noexcept {
      return i <= rhs.i;
    }
    constexpr bool operator>(const self_type rhs) const noexcept {
      return i > rhs.i;
    }
    constexpr bool operator>=(const self_type rhs) const noexcept {
      return i >= rhs.i;
    }
    constexpr bool operator==(const self_type rhs) const noexcept {
      return i == rhs.i;
    }
    constexpr bool operator!=(const self_type rhs) const noexcept {
      return i != rhs.i;
    }
    constexpr self_type& operator+=(const difference_type rhs) noexcept {
      i += rhs;
      return *this;
    }
    constexpr self_type& operator-=(const difference_type rhs) noexcept {
      i -= rhs;
      return *this;
    }
  };
  template <class T>
  constexpr integral_iterator<T> make_int_itr(const T i) noexcept {
    return integral_iterator<T>(i);
  }
  class rep {
    const usize f, l;

  public:
    constexpr rep(const usize f, const usize l) noexcept : f(f), l(l) {}
    constexpr auto begin() const noexcept { return make_int_itr(f); }
    constexpr auto end() const noexcept { return make_int_itr(l); }
  };
  class revrep {
    const usize f, l;

  public:
    revrep(const usize f, const usize l) noexcept : f(l), l(f) {}
    auto begin() const noexcept {
      return std::make_reverse_iterator(make_int_itr(f));
    }
    auto end() const noexcept {
      return std::make_reverse_iterator(make_int_itr(l));
    }
  };
  template <class T> auto md_vec(const usize n, const T& value) {
    return std::vector<T>(n, value);
  }
  template <class... Args> auto md_vec(const usize n, Args... args) {
    return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
  }
  template <class T> constexpr T difference(const T& a, const T& b) {
    return a < b ? b - a : a - b;
  }
  template <class T> T scan() {
    T ret;
    std::cin >> ret;
    return ret;
  }

} // namespace n91

#include <cstdint>

namespace n91 {

  constexpr std::uint_fast64_t totient(std::uint_fast64_t x) noexcept {
    using u64 = std::uint_fast64_t;
    u64 ret = x;
    for (u64 i = static_cast<u64>(2); i * i <= x; ++i) {
      if (x % i == static_cast<u64>(0)) {
        ret -= ret / i;
        x /= i;
        while (x % i == static_cast<u64>(0)) {
          x /= i;
        }
      }
    }
    if (x != static_cast<u64>(1)) {
      ret -= ret / x;
    }
    return ret;
  }

  template <std::uint_fast64_t Modulus,
    std::uint_fast64_t InverseExp =
    totient(Modulus) - static_cast<std::uint_fast64_t>(1)>
    class modint {
    using u64 = std::uint_fast64_t;

    static_assert(Modulus < static_cast<u64>(1) << static_cast<u64>(32),
      "Modulus must be less than 2**32");

    u64 a;

    constexpr modint& negate() noexcept {
      if (a != static_cast<u64>(0)) {
        a = Modulus - a;
      }
      return *this;
    }

    public:
      constexpr modint(const u64 x = static_cast<u64>(0)) noexcept
        : a(x% Modulus) {}
      constexpr u64& value() noexcept { return a; }
      constexpr const u64& value() const noexcept { return a; }
      constexpr modint operator+() const noexcept { return modint(*this); }
      constexpr modint operator-() const noexcept { return modint(*this).negate(); }
      constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
      }
      constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
      }
      constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
      }
      constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
      }
      constexpr modint& operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
          a -= Modulus;
        }
        return *this;
      }
      constexpr modint& operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
          a += Modulus;
        }
        a -= rhs.a;
        return *this;
      }
      constexpr modint& operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
      }
      constexpr modint& operator/=(modint rhs) noexcept {
        u64 exp = InverseExp;
        while (exp) {
          if (exp % static_cast<u64>(2) != static_cast<u64>(0)) {
            *this *= rhs;
          }
          rhs *= rhs;
          exp /= static_cast<u64>(2);
        }
        return *this;
      }
      constexpr bool operator==(const modint rhs) const noexcept {
        return a == rhs.a;
      }
      constexpr bool operator!=(const modint rhs) const noexcept {
        return a != rhs.a;
      }
  };

  template <class T, std::uint_fast64_t v> class modint_constant {
  public:
    static constexpr T value = static_cast<T>(v);

    using value_type = T;
  };

} // namespace n91

#include <functional>
#include <utility>

namespace n91 {

  template <class T, class U, class Operate = std::multiplies<T>>
  constexpr T power(T base, U exp, const Operate & oper = Operate(),
    T iden = static_cast<T>(1)) {
    while (exp != static_cast<U>(0)) {
      if (exp % static_cast<U>(2) != static_cast<U>(0)) {
        iden = oper(iden, base);
      }
      exp /= static_cast<U>(2);
      base = oper(base, base);
    }
    return iden;
  }

} // namespace n91

#include <vector>

namespace n91 {

  template <class T> class fact_binom {
  public:
    using value_type = T;
    using container_type = std::vector<value_type>;
    using size_type = typename container_type::size_type;

  private:
    container_type factrial, inv_fact;

  public:
    fact_binom() : factrial(), inv_fact() {}
    explicit fact_binom(const size_type n) : factrial(n + 1), inv_fact(n + 1) {
      factrial[0] = static_cast<value_type>(1);
      for (size_type i = 0; i != n; ++i) {
        factrial[i + 1] = static_cast<value_type>(i + 1) * factrial[i];
      }
      inv_fact[n] = static_cast<value_type>(1) / factrial[n];
      for (size_type i = n; i != 0; --i) {
        inv_fact[i - 1] = inv_fact[i] * static_cast<value_type>(i);
      }
    }

    value_type operator()(const size_type n, const size_type r) const {
      return factrial[n] * inv_fact[r] * inv_fact[n - r];
    }
  };

} // namespace n91

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <utility>

namespace std {
  template <typename T> class BIT {
  private:
    int n;
    vector<T> bit;

  public:
    // 0_indexed で i 番目の要素に x を加える
    void add(int i, T x) {
      i++;
      while (i < n) {
        bit[i] += x, i += i & -i;
      }
    }
    // 0_indexed で [0,i] の要素の和(両閉区間！！)
    T sum(int i) {
      i++;
      T s = 0;
      while (i > 0) {
        s += bit[i], i -= i & -i;
      }
      return s;
    }
    BIT() {}
    //初期値がすべて0の場合
    BIT(int sz) : n(sz + 1), bit(n, 0) {}
    BIT(const vector<T>& v) : n((int)v.size() + 1), bit(n, 0) {
      for (int i = 0; i < n - 1; i++) {
        add(i, v[i]);
      }
    }
    void print() {
      for (int i = 0; i < n - 1; i++) {
        cout << sum(i) - sum(i - 1) << " ";
      }
      cout << "\n";
    }
    //-1スタート
    void print_sum() {
      for (int i = 0; i < n; i++) {
        cout << sum(i - 1) << " ";
      }
      cout << "\n";
    }
  };

  // u を昇順にソートするのに必要な交換回数(転倒数) (u は {0,..., n-1}
  // からなる重複を許した長さ n の数列)
  long long inv_count(const vector<int>& u) {
    int n = (int)u.size();
    BIT<int> bt(n);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      ans += i - bt.sum(u[i]);
      bt.add(u[i], 1);
    }
    return ans;
  }
} // namespace std

namespace n91 {

  void main_() {
    const usize n = scan<usize>();
    const usize k = scan<usize>();
    std::vector<int> p(n);
    for (auto& e : p) {
      std::cin >> e;
      --e;
    }
    if (k != n) {
      const auto inv = std::inv_count(p);
      std::cout << ((inv % 2 == 0 || k % 2 == 0) ? "Yes" : "No") << std::endl;
      return;
    }
    for (const auto i : rep(1_z, n)) {
      if ((p[i - 1_z] + 1_z - p[i]) % n != 0_z) {
        std::cout << "No" << std::endl;
        return;
      }
    }
    std::cout << "Yes" << std::endl;
  }

} // namespace n91

int main() {
  n91::main_();
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3640
final_rank: 8

code_snippet: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <sys/types.h>
#include <unistd.h>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


struct BIT{
  vector<int> bit;
  int n;
  //1-indexed
  BIT(){init(-1);}
  BIT(int n_){init(n_);}
  void init(int n_){
    n=n_;
    bit.clear();
    bit.resize(n+1,0);
  }
  int sum(int i){
    int s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
  void add(int i,int x){
    if(i==0) return;
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  int sum0(int i){
    return sum(i+1);
  }
  void add0(int i,int x){
    add(i+1,x);
  }
};
signed main(void) {
    int n,k;
    cin >> n >> k;
    int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  if(n == k){
      rep(i,n)if(a[i] == 1){
          rep(j,n)if(a[(i+j)%n] != a[i]+j){
              cout << "No" << endl;
              return 0;
          }
      }
      cout << "Yes" << endl;
      return 0; 
  }
  if(k%2 == 0){
      cout << "Yes" << endl;
      return 0;
  }
  reverse(a,a+n);
  BIT bit(n+10);
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=bit.sum(a[i]);
    bit.add(a[i],1);
}
  if(ans%2){
      cout << "No" << endl;
  }else{
      cout << "Yes" << endl;
  }

}
accuracy: 1
time_ms: 20
memory_kb: 4388
final_rank: 11

code_snippet: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <sys/types.h>
#include <unistd.h>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef pair<int, pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }


struct BIT {
	vector<int> bit;
	int n;
	//1-indexed
	BIT() { init(-1); }
	BIT(int n_) { init(n_); }
	void init(int n_) {
		n = n_;
		bit.clear();
		bit.resize(n + 1, 0);
	}
	int sum(int i) {
		int s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	void add(int i, int x) {
		if (i == 0) return;
		while (i <= n) {
			bit[i] += x;
			i += i & -i;
		}
	}
	int sum0(int i) {
		return sum(i + 1);
	}
	void add0(int i, int x) {
		add(i + 1, x);
	}
};
signed main(void) {
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	if (k % 2 == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	if (n == k) {
		set<int>S;
		for (int i = 0; i < n; ++i) {
			S.insert((a[i]-i+n)%n);
		}
		if (S.size() == 1) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		return 0;
	}
	reverse(a, a + n);
	BIT bit(n + 10);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += bit.sum(a[i]);
		bit.add(a[i], 1);
	}
	if (ans % 2) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

}
accuracy: 0.8771929824561403
time_ms: 20
memory_kb: 4356
final_rank: 19

code_snippet: #include <iostream>
#include <string.h>
#include <vector>
using namespace std;

const int MAXN = 100000, MOD = 1000000007;

int t[MAXN + 10];

void add(int v, int d)
{
    for (; v <= MAXN; v += (v & (-v)))
        t[v] += d;
}

int sum(int r)
{
    int ans = 0;
    for (; r > 0; r -= (r & (-r)))
        ans += t[r];
    return ans;
}

int sum(int l, int r)
{
    return sum(r) - sum(l - 1);
}

int index(vector<int> p, int mod)
{
    int n = p.size();
    memset(t, 0, sizeof t);
    for (int i = 1; i <= n; ++i)
        add(i, 1);
    int fact[MAXN + 10];
    fact[0] = 1 % mod;
    for (int i = 1; i <= n; ++i)
        fact[i] = fact[i - 1] * 1ll * i % mod;
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        int id = sum(p[i] - 1);
        ans = (ans + id * 1ll * fact[n - 1 - i]) % mod;
        add(p[i], -1);
    }
    return ans;
}

int parity(vector<int> p)
{
    int n = p.size();
    memset(t, 0, sizeof t);
    int ans = 0;
    for (int i = n - 1; i >= 0; --i)
    {
        int smaller = sum(p[i] - 1);
        ans = (ans + smaller) % 2;
        add(p[i], 1);
    }
    return ans;
}

int main()
{
    cin.sync_with_stdio(false);
    int CASE = 1;
    int n, k;
    vector<int> p, q;
    cin >> n >> k;
    p.resize(n);
    q.resize(n);
    for (int i = 0; i < n; ++i)
        cin >> p[i];
    for (int i = 0; i < n; ++i)
        q[i] = i + 1;
    if (k == n)
    {
        int start = -1;
        for (int i = 0; i < n; ++i)
        {
            if (q[i] == p[0])
            {
                start = i;
                break;
            }
        }
        bool good = true;
        for (int i = 0; i < n; ++i)
        {
            if (p[i] != q[(i + start) % n])
            {
                good = false;
                break;
            }
        }
        if (good)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else if (k % 2 == 0)
    {
        int id = index(q, MOD);
        cout << "Yes" << endl;
    }
    else
    {
        if (parity(p) == parity(q))
        {
            int id = index(q, MOD);
            if (index(q, 2) == 1)
                id = (id + MOD - 1) % MOD;
            id = id * 500000004ll % MOD;
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4652
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define dbg(x) cout<<#x<<"="<<x<<endl

using P=pair<int,int>;

int main(){
    int n,k;
    cin>>n>>k;
    if(k==2){
        cout<<"Yes"<<endl;
        return 0;
    }
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin>>p[i];
        --p[i];
    }
    if(n==k){
        for (int i = 0; i < n-1; ++i) {
            if(p[i]!=n-1&&p[i]>p[i+1]){
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
        return 0;
    }

    vector<bool> vis(n,false);
    int ms=0;
    for (int i = 0; i < n; ++i) {
      if(vis[i])continue;
      int crt=i;
      int d=0;
      while(!vis[crt]){
        vis[crt]=true;
        d++;
        crt=p[crt];
      }
      d%=2;
      if(d==0)ms++;
    }
    ms%=2;

    if(k%2==1&&ms%2==1)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3300
final_rank: 4

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
set<vector<int> > st;

void dfs(vector<int> a,int n,int k){
    for(int i=0;i<=n-k;i++){
        for(int t = 1;t<=k-1;t++){
            vector<int>b(n);
            rep(j,n){
                b[j] = a[j];
            }  
        
            rep(j,k){
                b[i+j] = a[i+j+t];
                if(i+j+t >= i+k){
                    b[i+j] = a[i+j+t-k];
                } 
            }
            if(st.count(b)){

            }else{
                st.insert(b);
                dfs(b,n,k);
            }
        }
    }

}
template<typename T> class BIT {
private:
	int n;
	vector<T> bit;
public:
	// 0_indexed で i 番目の要素に x を加える
	void add(int i, T x){
		i++;
		while(i < n){
			bit[i] += x, i += i & -i;
		}
	}
	// 0_indexed で [0,i] の要素の和(両閉区間！！)
	T sum(int i){
		i++;
		T s = 0;
		while(i > 0){
			s += bit[i], i -= i & -i;
		}
		return s;
	}
	BIT(){}
	//初期値がすべて0の場合
	BIT(int sz) : n(sz+1), bit(n, 0){}
	BIT(const vector<T>& v) : n((int)v.size()+1), bit(n, 0){
		for(int i = 0; i < n-1; i++){
			add(i,v[i]);
		}
	}
	void print(){
		for(int i = 0; i < n-1; i++){
			cout << sum(i) - sum(i-1) << " ";
		}
		cout << "\n";
	}
	//-1スタート
	void print_sum(){
		for(int i = 0; i < n; i++){
			cout << sum(i-1) << " ";
		}
		cout << "\n";
	}
};
 
// u を昇順にソートするのに必要な交換回数(転倒数) (u は {0,..., n-1} からなる重複を許した長さ n の数列)
long long inv_count(const vector<int>& u)
{
	int n = (int)u.size();
	BIT<int> bt(n);
	long long ans = 0;
	for(int i = 0; i < n; i++){
		ans += i - bt.sum(u[i]);
		bt.add(u[i], 1);
	}
	return ans;
}
 
// u を v に変換するのに必要な交換回数(転倒数)
// (u, v は {0,..., n-1} からなる重複を許した長さ n の数列. ただし u, v 全体で各数字の個数は一致するものとする)
long long inv_count(const vector<int>& u, const vector<int>& v)
{
    int n = (int)u.size();
    vector<vector<int> > p(n);
    BIT<int> bt(n);
    for(int i = n-1; i >= 0; --i){
        p[u[i]].push_back(i);
    }
    long long ans = 0;
    for(int i = 0; i < n; ++i){
        int pos = p[v[i]].back();
        p[v[i]].pop_back();
        ans += pos - bt.sum(pos);
        bt.add(pos, 1);
    }
    return ans;
}
int main(){
    // for(int n = 2;n<=8;n++){
    //     for(int k=2;k<=n;k++){
    //         st.clear();
    //         vector<int>v(n);
    //         rep(i,n){
    //             v[i] = i;
    //         }
    //         dfs(v,n,k);
    //         int sm = 1;
    //         rep(i,n){
    //             sm *=(i+1);
    //         }
    //         cout << n << " " << k << endl;
    //         cout << sm << endl;
    //         cout << st.size() << endl;
    //         // for(auto s:st){
    //         //     for(auto x:s){
    //         //         cout << x << " ";
    //         //     }
    //         //     cout << endl;
    //         // }
    //     }
    // }
    int n,k;
    cin >> n >> k;
    vector<int>a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    if(n==k){
        int id = 0;
        rep(i,n){
            if(a[i]==0){
                id = i;
            }
        }
        rep(i,n){
            int k = id+i;
            k%=n;
            
            if(a[k]!=i){
                cout <<"No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }else{
        if(k%2==0){
            cout << "Yes" << endl;
        }else{
            if(inv_count(a)%2){
                cout << "No" << endl;
            }else{
                cout << "Yes" << endl;
            }
        }
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3624
final_rank: 7

code_snippet: #if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>

/* ----- Type Alias ----- */
using Int = long long int;
using Real = long double;
using std::pair;
using std::string;
using std::tuple;
using std::vector;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = vector<vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// const Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

struct SegmentTree {
    int length;
    std::vector<int> dat;

    int query(int ql, int qr, int nidx, int nl, int nr) {
        if (nr <= ql || qr <= nl) return 0;
        if (ql <= nl && nr <= qr) return dat[nidx];
        int vl = query(ql, qr, nidx * 2, nl, (nl + nr) / 2);
        int vr = query(ql, qr, nidx * 2 + 1, (nl + nr) / 2, nr);
        return vl + vr;
    }

    SegmentTree(int N) : length(1) {
        while (length < N) length <<= 1;
        dat.assign(length * 2, 0);
    }

    // half-open interval [ql, qr)
    int query(int ql, int qr) { return query(ql, qr, 1, 0, length); }

    void update(int idx, int e) {
        int nidx = idx + length;
        dat[nidx] += e;
        while (nidx > 0) {
            nidx >>= 1;
            dat[nidx] = dat[nidx * 2] + dat[nidx * 2 + 1];
        }
    }
};

int main() {
    int n, k;
    std::cin >> n >> k;

    vector<int> p(n);
    for (auto& x : p) {
        std::cin >> x;
        --x;
    }

    if (k == n) {
        int i;
        for (i = 0; p[i] != 0; ++i) {}
        for (int j = 0; j < n; ++j) {
            if (p[(i + j) % n] != j) {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
        std::cout << "Yes" << std::endl;
        return 0;
    }

    Int rev = 0;
    SegmentTree seg(n);
    for (auto x : p) {
        rev += seg.query(x + 1, n);
        seg.update(x, 1);
    }

    if (k % 2 == 1 && rev % 2 == 1) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4152
final_rank: 17

code_snippet: #include "bits/stdc++.h"

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

class Add_Segment_Tree {
	vector<long long int>v;
	vector<int>l;
	vector<int>r;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = Update(place * 2) + Update(place * 2 + 1);
		return v[place];
	}
	void Sum(int a, int b, int place) {
		if (l[place] >= a&&r[place] <= b) {
			ret += v[place];
			return;
		}
		if (l[place] > b || r[place] < a) return;
		Sum(a, b, place * 2);
		Sum(a, b, place * 2 + 1);
		return;
	}
public:
	void Left(int place) {
		if (place >= v.size() / 2) {
			l[place] = place - v.size() / 2;
			return;
		}
		Left(place * 2);
		Left(place * 2 + 1);
		l[place] = l[place * 2];
		return;
	}
	void Right(int place) {
		if (place >= v.size() / 2) {
			r[place] = place - v.size() / 2;
			return;
		}
		Right(place * 2);
		Right(place * 2 + 1);
		r[place] = r[place * 2 + 1];
		return;
	}
	Add_Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2)num *= 2;
		l.resize(num);
		r.resize(num);
		v.resize(num, 0);
		Left(1);
		Right(1);
	}
	void Add(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] += num;
		if (!update)return;
		place /= 2;
		while (place) {
			v[place] = v[place * 2] + v[place * 2 + 1];
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 0;
		Sum(a, b, 1);
		return ret;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N>>K;
	vector<int>v(N);
	for(auto &i:v)cin>>i;
	long long int box=0;
	Add_Segment_Tree asg(N+1);
	for(int i=0;i<N;i++){
		box+=asg.Sum(v[i],N);
		asg.Add(v[i],1,true);
	}
	if(box%2&&K%2){
		cout<<"No\n";
		return 0;
	}
	if(N==K){
		for(int i=0;i<N;i++){
			if((v[i]+1)%N!=(v[(i+1)%N])%N){
				cout<<"No\n";
				return 0;
			}
		}
	}
	cout<<"Yes\n";
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7344
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<class Z> Z rng(Z a, Z b) {
  static mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<Z>(a, b - 1)(mt);
}

namespace RBST {
  constexpr int lim = 1 << 20;
  using T = pair<int, int>;
  constexpr T e = {1e9, -1};
  T op(const T& a, const T& b) { return min(a, b); }
  T op(const T& a, const T& b, const T& c) { return op(op(a, b), c); }
  using U = int;
  constexpr U id = 0;
  void ap(const U& f, T& a) { a.second += f; }
  void cp(const U& g, U& f) { f += g; }

  struct Node;
  using Tree = Node*;
  struct Node {
    Tree lch, rch;
    int sz, h;
    T val, acc = e, inv = e;
    U laz = id;
    bool rev;
  };
  Tree nil = new Node();

  Tree update(Tree t) {
    t->sz = t->lch->sz + 1 + t->rch->sz;
    t->h = max(t->lch->h, t->rch->h) + 1;
    t->acc = op(t->lch->acc, t->val, t->rch->acc);
    t->inv = op(t->rch->inv, t->val, t->lch->inv);
    assert(t->laz == id);
    assert(!t->rev);
    return t;
  }
  Node pool[lim];
  Tree make(const T& v, Tree l = nil, Tree r = nil) {
    static int p = 0;
    assert(p < lim);
    Tree t = pool + p++;
    t->lch = l, t->rch = r;
    t->val = v;
    return update(t);
  }

  void apply(Tree t, const U& f) {
    if (t == nil) return;
    ap(f, t->val);
    ap(f, t->acc);
    ap(f, t->inv);
    cp(f, t->laz);
  }
  void reverse(Tree t) {
    if (t == nil) return;
    swap(t->lch, t->rch);
    swap(t->acc, t->inv);
    t->rev ^= true;
  }
  void push(Tree t) {
    if (!(t->laz == id)) {
      apply(t->lch, t->laz);
      apply(t->rch, t->laz);
      t->laz = id;
    }
    if (t->rev) {
      reverse(t->lch);
      reverse(t->rch);
      t->rev = false;
    }
  }

  template<class Itr> Tree build(Itr first, Itr last) {
    int n = distance(first, last);
    if (!n) return nil;
    Itr middle = next(first, n >> 1);
    return make(*middle, build(first, middle), build(next(middle), last));
  }
  template<class Itr> Itr dump(Tree t, Itr res) {
    if (t == nil) return res;
    push(t);
    res = dump(t->lch, res);
    *res++ = t->val;
    return dump(t->rch, res);
  }
  void rebuild(Tree& t) {
    V<T> v(t->sz);
    dump(t, begin(v));
    t = build(begin(v), end(v));
  }

  Tree merge(Tree l, Tree r) {
    if (l == nil) return r;
    if (r == nil) return l;
    if (rng(0, l->sz + r->sz) < l->sz) {
      push(l);
      l->rch = merge(l->rch, r);
      return update(l);
    } else {
      push(r);
      r->lch = merge(l, r->lch);
      return update(r);
    }
  }
  Tree merge(Tree l, Tree m, Tree r) { return merge(merge(l, m), r); }
  pair<Tree, Tree> split(Tree t, int i) {
    assert(0 <= i and i <= t->sz);
    if (t == nil) return {nil, nil};
    push(t);
    if (i <= t->lch->sz) {
      Tree l;
      tie(l, t->lch) = split(t->lch, i);
      return {l, update(t)};
    } else {
      Tree r;
      tie(t->rch, r) = split(t->rch, i - t->lch->sz - 1);
      return {update(t), r};
    }
  }
  tuple<Tree, Tree, Tree> split(Tree t, int l, int r) {
    assert(0 <= l and l <= r and r <= t->sz);
    Tree lt, mt, rt;
    tie(lt, rt) = split(t, r);
    tie(lt, mt) = split(lt, l);
    return make_tuple(lt, mt, rt);
  }
  void insert(Tree& t, int i, const T& v) {
    assert(0 <= i and i <= t->sz);
    if (!rng(0, t->sz + 1)) {
      Tree l, r;
      tie(l, r) = split(t, i);
      t = make(v, l, r);
      return;
    }
    push(t);
    if (i <= t->lch->sz) {
      insert(t->lch, i, v);
    } else {
      insert(t->rch, i - t->lch->sz - 1, v);
    }
    t = update(t);
  }
  void erase(Tree& t, int i) {
    assert(0 <= i and i < t->sz);
    push(t);
    if (i == t->lch->sz) {
      t = merge(t->lch, t->rch);
    } else if (i < t->lch->sz) {
      erase(t->lch, i);
      t = update(t);
    } else {
      erase(t->rch, i - t->lch->sz - 1);
      t = update(t);
    }
  }

  T get(Tree t, int i) {
    assert(0 <= i and i < t->sz);
    if (i == t->lch->sz) return t->val;
    push(t);
    if (i < t->lch->sz) return get(t->lch, i);
    return get(t->rch, i - t->lch->sz - 1);
  }
  void set(Tree t, int i, const T& a) {
    assert(0 <= i and i < t->sz);
    push(t);
    if (i == t->lch->sz) {
      t->val = a;
    } else if (i < t->lch->sz) {
      set(t->lch, i, a);
    } else {
      set(t->rch, i - t->lch->sz - 1, a);
    }
    update(t);
  }
  T acc(Tree t, int l, int r) {
    if (l <= 0 and t->sz <= r) return t->acc;
    push(t);
    T resl = l < t->lch->sz ? acc(t->lch, l, r) : e;
    T resr = t->lch->sz + 1 < r ? acc(t->rch, l - t->lch->sz - 1, r - t->lch->sz - 1) : e;
    T resm = l <= t->lch->sz and t->lch->sz < r ? t->val : e;
    return op(resl, resm, resr);
  }
  void act(Tree t, int l, int r, const U& f) {
    if (l <= 0 and t->sz <= r) {
      apply(t, f);
      return;
    }
    push(t);
    if (l < t->lch->sz) act(t->lch, l, r, f);
    if (t->lch->sz + 1 < r) act(t->rch, l - t->lch->sz - 1, r - t->lch->sz - 1, f);
    if (l <= t->lch->sz and t->lch->sz < r) ap(f, t->val);
    update(t);
  }
  void reverse(Tree& t, int l, int r) {
    assert(0 <= l and l <= r and r <= t->sz);
    Tree lt, mt, rt;
    tie(lt, mt, rt) = split(t, l, r);
    reverse(mt);
    t = merge(lt, mt, rt);
  }
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  V< pair<int, int> > v(n);
  for (int i = 0; i < n; ++i) {
    int p; cin >> p;
    v[i] = {p, i};
  }
  auto t = RBST::build(begin(v), end(v));

  auto fn = [&](int l, int m, int r) -> void {
    act(t, l, m, r - m);
    act(t, m, r, -(m - l));
    RBST::Tree tl, tm, tr;
    tie(tl, tm, tr) = split(t, l, r);
    RBST::Tree ml, mr;
    tie(ml, mr) = split(tm, m - l);
    t = merge(tl, merge(mr, ml), tr);
  };

  for (int i = 0; i + k <= n; ++i) {
    int j = acc(t, i, n).second;
    if (j - i >= k - 1) {
      int nj = i + (j - i) % (k - 1);
      fn(nj, j, j + 1);
      j = nj;
    }
    if (j == i) continue;
    fn(i, j, i + k);
  }
  dump(t, begin(v));
  cout << (is_sorted(begin(v), end(v)) ? "Yes" : "No") << '\n';
}
accuracy: 0.05263157894736842
time_ms: 10
memory_kb: 60520
final_rank: 20

code_snippet: #include <bits/stdc++.h>

using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0):n(n_),bit(n_+1){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
	int lower_bound(T k)//k<=sum(ret)
	{
		if(k<=0)return 0;
		int ret=0,i=1;
		while((i<<1)<=n)i<<=1;
		for(;i;i>>=1)
			if(ret+i<=n&&bit[ret+i]<k)k-=bit[ret+=i];
		return ret+1;
	}
};
int main(){
    unsigned long N, K;
    cin >> N >> K;
    if(N == K){
        vector<unsigned long> P(N);
        for(auto& i : P)cin >> i;
        P.push_back(P[0]);
        for(unsigned long i = 0; i < N; ++i)if((P[i] + 1 + N - P[i + 1]) % N)return 0 & puts("No");
		puts("Yes");
		return 0;
    }
    if(~K & 1)return 0 & puts("Yes");
    vector<unsigned long> P(N);
    for(auto& i : P)cin >> i;
    BIT<int>bit(N);
	long long T=0;
	for(int i=0;i<N;i++)
	{
		T+=i-bit.sum(P[i]);
		bit.add(P[i],1);
	}
	cout<<(T%2?"No":"Yes")<<endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4460
final_rank: 12

code_snippet: #include <cstdio>
#include <cstdint>
#include <vector>
#include <array>
#include <utility>
#include <algorithm>

class bit_vector {
  size_t n;
  static constexpr size_t nbit = 64;
  std::vector<intmax_t> raw;
  std::vector<int> acc;

  int popcount(uintmax_t x) const {
    return __builtin_popcountll(x);
  }

public:
  bit_vector() {}

  bit_vector(const std::vector<bool>& b): n(b.size()) {
    raw.assign(n/nbit+1, 0);
    for (size_t i = 0; i < n; ++i)
      if (b[i]) raw[i/nbit] |= intmax_t(1) << (i % nbit);

    acc.assign(n/nbit+1, 0);
    for (size_t i = 1; i < acc.size(); ++i)
      acc[i] = acc[i-1] + popcount(raw[i-1]);
  }

  size_t rank1(size_t k) const {
    size_t large = k / nbit;
    size_t small = k % nbit;
    size_t res = acc[large];
    if (small > 0) res += popcount(raw[large] & ((uintmax_t(1) << small) - 1));
    return res;
  }

  size_t rank0(size_t k) const {
    return k - rank1(k);
  }

  size_t select1(size_t k) const {
    if (k == 0) return 0;
    size_t lb = 0;
    size_t ub = n;
    while (ub-lb > 1) {
      size_t mid = (lb+ub) >> 1;
      ((rank1(mid) < k)? lb:ub) = mid;
    }
    if (rank1(ub) < k) return -1;
    return ub;
  }

  size_t select0(size_t k) const {
    if (k == 0) return 0;
    size_t lb = 0;
    size_t ub = n;
    while (ub-lb > 1) {
      size_t mid = (lb+ub) >> 1;
      ((rank0(mid) < k)? lb:ub) = mid;
    }
    if (rank0(ub) < k) return -1;
    return ub;
  }

  size_t rank(int x, size_t k) const {
    return x? rank1(k) : rank0(k);
  }

  size_t select(int x, size_t k) const {
    return x? select1(k) : select0(k);
  }

  bool operator [](size_t k) const {
    size_t large = k / nbit;
    size_t small = k % nbit;
    return raw[large] >> small & 1;
  }
};

template <class Tp, size_t bitlen = 8 * sizeof(Tp)>
class wavelet_matrix {
public:
  using value_type = typename std::make_unsigned<Tp>::type;

private:
  std::vector<value_type> c;
  std::vector<size_t> zeros;
  size_t n;
  std::array<bit_vector, bitlen> a;

  size_t start_index(value_type x) const {
    size_t s = 0;
    size_t t = 0;
    for (size_t i = bitlen; i-- > 1;) {
      size_t j = bitlen-i-1;
      if (x >> i & 1) {
        s = zeros[j] + a[j].rank1(s);
        t = zeros[j] + a[j].rank1(t);
      } else {
        s = a[j].rank0(s);
        t = a[j].rank0(t);
      }
    }
    return s;
  }

public:
  template <class InputIt>
  wavelet_matrix(InputIt first, InputIt last):
    c(first, last), zeros(bitlen), n(c.size())
  {
    std::vector<value_type> whole = c;
    for (size_t i = bitlen; i--;) {
      std::vector<value_type> zero, one;
      std::vector<bool> vb(n);
      for (size_t j = 0; j < n; ++j) {
        ((whole[j] >> i & 1)? one:zero).push_back(whole[j]);
        vb[j] = (whole[j] >> i & 1);
      }

      zeros[bitlen-i-1] = zero.size();
      a[bitlen-i-1] = bit_vector(vb);
      if (i == 0) break;
      whole = std::move(zero);
      whole.insert(whole.end(), one.begin(), one.end());
    }
  }

  size_t rank(value_type x, size_t t) const {
    if (t == 0) return 0;
    size_t s = 0;
    for (size_t i = bitlen; i--;) {
      size_t j = bitlen-i-1;
      if (x >> i & 1) {
        s = zeros[j] + a[j].rank1(s);
        t = zeros[j] + a[j].rank1(t);
      } else {
        s = a[j].rank0(s);
        t = a[j].rank0(t);
      }
    }
    return t - s;
  }

  std::pair<bool, value_type> max_lt(value_type x, size_t s, size_t t) const {
    return max_le(x-1, s, t);
  }
  std::pair<bool, value_type> max_le(value_type x, size_t s, size_t t) const {
    if (s == t) return {false, 0};
    size_t ri = bitlen+1;
    size_t rs = -1;
    size_t rt = -1;
    bool tight = true;
    bool reverted = false;
    value_type res = 0;
    for (size_t i = bitlen; i--;) {
      size_t j = bitlen-i-1;
      size_t z = a[j].rank0(t) - a[j].rank0(s);
      size_t tg = (tight? (x >> i & 1) : 1);
      if (reverted) tg = 0;

      bool ok0 = (z > 0);
      bool ok1 = (z < t-s);
      size_t ch = 0;

      reverted = false;
      if (tg == 1) {
        if (ok0) {
          ri = i;
          rs = s;
          rt = t;
        }
        if (ok1) {
          ch = 1;
        } else {
          tight = false;
        }
      } else if (!ok0 && tight) {
        if (ri > bitlen) return {false, 0};
        i = ri+1;
        s = rs;
        t = rt;
        tight = false;
        value_type mask = (static_cast<value_type>(1) << i) - 1;
        res |= mask;
        res ^= mask;
        reverted = true;
        continue;
      }

      if (ch == 0) {
        s = a[j].rank0(s);
        t = a[j].rank0(t);
      } else {
        s = zeros[j] + a[j].rank1(s);
        t = zeros[j] + a[j].rank1(t);
        res |= static_cast<value_type>(1) << i;
      }
    }
    return {true, res};
  }
  std::pair<bool, value_type> min_gt(value_type x, size_t s, size_t t) const {
    return min_ge(x+1, s, t);
  }
  std::pair<bool, value_type> min_ge(value_type x, size_t s, size_t t) const {
    if (s == t) return {false, 0};
    size_t ri = bitlen+1;
    size_t rs = -1;
    size_t rt = -1;
    bool tight = true;
    bool reverted = false;
    value_type res = 0;
    for (size_t i = bitlen; i--;) {
      size_t j = bitlen-i-1;
      size_t z = a[j].rank0(t) - a[j].rank0(s);
      size_t tg = (tight? (x >> i & 1) : 0);
      if (reverted) tg = 1;

      bool ok0 = (z > 0);
      bool ok1 = (z < t-s);
      size_t ch = 1;

      reverted = false;
      if (tg == 0) {
        if (ok1) {
          ri = i;
          rs = s;
          rt = t;
        }
        if (ok0) {
          ch = 0;
        } else {
          tight = false;
        }
      } else if (!ok1 && tight) {
        if (ri > bitlen) return {false, 0};
        i = ri+1;
        s = rs;
        t = rt;
        tight = false;
        value_type mask = (static_cast<value_type>(1) << ri) - 1;
        res |= mask;
        res ^= mask;
        reverted = true;
        continue;
      }

      if (ch == 0) {
        s = a[j].rank0(s);
        t = a[j].rank0(t);
      } else {
        s = zeros[j] + a[j].rank1(s);
        t = zeros[j] + a[j].rank1(t);
        res |= static_cast<value_type>(1) << i;
      }
    }
    return {true, res};
  }

  value_type quantile(size_t k, size_t s, size_t t) const {
    value_type res = 0;
    for (size_t i = bitlen; i--;) {
      size_t j = bitlen-i-1;
      size_t z = a[j].rank0(t) - a[j].rank0(s);
      if (k < z) {
        s = a[j].rank0(s);
        t = a[j].rank0(t);
      } else {
        res |= static_cast<value_type>(1) << i;
        s = zeros[j] + a[j].rank1(s);
        t = zeros[j] + a[j].rank1(t);
        k -= z;
      }
    }
    return res;
  }

  std::array<size_t, 3> rank_three_way(value_type x, size_t t) const {
    if (t == 0) return {0, 0, 0};

    size_t lt = 0;
    size_t eq = t;
    size_t gt = 0;

    size_t s = 0;
    for (size_t i = bitlen; i--;) {
      size_t j = bitlen-i-1;
      size_t tmp = (t - s);
      if (x >> i & 1) {
        s = zeros[j] + a[j].rank1(s);
        t = zeros[j] + a[j].rank1(t);
        size_t d = tmp - (t-s);
        eq -= d;
        lt += d;
      } else {
        s = a[j].rank0(s);
        t = a[j].rank0(t);
        size_t d = tmp - (t-s);
        eq -= d;
        gt += d;
      }
    }
    return {lt, eq, gt};
  }

  std::array<size_t, 3> xored_rank_three_way(value_type x, value_type y, size_t t) const {
    if (t == 0) return {0, 0, 0};

    size_t lt = 0;
    size_t eq = t;
    size_t gt = 0;

    size_t s = 0;
    for (size_t i = bitlen; i--;) {
      size_t j = bitlen-i-1;
      size_t tmp = (t - s);
      if ((x ^ y) >> i & 1) {
        s = zeros[j] + a[j].rank1(s);
        t = zeros[j] + a[j].rank1(t);
      } else {
        s = a[j].rank0(s);
        t = a[j].rank0(t);
      }

      size_t d = tmp - (t-s);
      eq -= d;
      if (y >> i & 1) {
        lt += d;
      } else {
        gt += d;
      }
    }
    return {lt, eq, gt};
  }

  size_t select(value_type x, size_t t) const {
    if (t == 0) return 0;
    size_t si = start_index(x);
    t += a[bitlen-1].rank(x & 1, si);
    t = a[bitlen-1].select(x & 1, t);

    for (size_t i = 1; i < bitlen; ++i) {
      size_t j = bitlen-i-1;
      if (x >> i & 1) t -= zeros[j];
      t = a[j].select(x >> i & 1, t);
    }

    return t;
  }

  value_type operator [](size_t t) const { return c[t]; }

  void inspect() const {
    for (size_t i = 0; i < bitlen; ++i) {
      fprintf(stderr, "%zu (%zu): ", i, zeros[i]);
      for (size_t j = 0; j < n; ++j)
        fprintf(stderr, "%d%c", a[i][j], j+1<n? ' ':'\n');
    }
  }
};


int main() {
  size_t n, k;
  scanf("%zu %zu", &n, &k);

  std::vector<size_t> p(n);
  for (auto& pi: p) scanf("%zu", &pi), --pi;

  if (n == k) {
    intmax_t a = p[0];
    for (size_t i = 1; i < n; ++i) {
      intmax_t b = (p[i] + n - i) % n;
      if (b < 0) b += n;
      if (a != b) return puts("No"), 0;
    }
    puts("Yes");
    return 0;
  }

  wavelet_matrix<size_t, 20> wm(p.begin(), p.end());
  intmax_t res = 0;
  for (size_t i = 0; i < n; ++i) {
    res += wm.rank_three_way(p[i], i)[2];
  }
  // fprintf(stderr, "%jd\n", res);

  if (res % 2 == 0) {
    puts("Yes");
  } else if (k % 2 == 0) {
    puts("Yes");
  } else {
    puts("No");
  }
}
accuracy: 1
time_ms: 40
memory_kb: 6944
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

ll n,k;
set<vector<ll> > s;

void dfs(vector<ll> v) {
  if(s.count(v)) return;
  s.in(v);
  rep(i,n-k+1) {
    vector<ll> a=v;
    rotate(a.begin()+i,a.begin()+i+1,a.begin()+i+k);
    dfs(a);
  }
}

class BIT{
public:
  ll n,bit[555555];
  BIT(){fill(bit,bit+555555,0);}
  void add(ll i,ll x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  ll sum(ll i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
};

BIT b;
ll calc(vector<ll> a) {
  b=BIT();
  b.n=n+1;
  ll ans=0;
  rep(i,a.size()) {
    b.add(a[i],1);
    ans+=b.sum(n+1)-b.sum(a[i]);
  }
  return ans;
}

void solve(vector<ll> a) {
  if(n==k) {
    int k=-1;
    rep(i,n) {
      if(a[i]==1) k=i;
    }
    rotate(a.begin(),a.begin()+k,a.end());
    rep(i,n) {
      if(i+1!=a[i]) {
        //pr("No");
        PR(a,a.size());
        exit(0);
        return;
      }
    }
    //pr("Yes");
    return;
  }
  vector<ll> v;
  rep(i,n-k) v.pb(a[i]);
  ll x=calc(v);
  v.clear();
  REP(i,n-k,n) v.pb(a[i]);
  ll y=calc(v);
  if(x%2==y%2);
  else {
    pr(x,y);
    PR(a,a.size()),exit(0);
  }
  //if(x%2==y%2) pr("Yes");
  //else pr("No"),exit(0);
}

void Main() {
  cin >> n >> k;
  vector<ll> a(n);
  /*
  rep(i,n) a[i]=i+1;
  dfs(a);
  tr(it,s) {
    vector<ll> v=*it;
    PR(v,v.size());
    pr(calc(v));
    //solve(v);
  }
  return;
  */
  rep(i,n) R a[i];
  if(n==k) {
    int k=-1;
    rep(i,n) {
      if(a[i]==1) k=i;
    }
    rotate(a.begin(),a.begin()+k,a.end());
    rep(i,n) {
      if(i+1!=a[i]) {
        pr("No");
        return;
      }
    }
    pr("Yes");
    return;
  }
  if(k%2==0) pr("Yes");
  else if(calc(a)%2==0) pr("Yes");
  else pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
accuracy: 1
time_ms: 10
memory_kb: 13104
final_rank: 3

code_snippet: #include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define ECHO OUT(solve())
#define YESNO OUT(three(solve(),YES,NO))
#define YesNo OUT(three(solve(),Yes,No))
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<tapu, Vtapu, greater<tapu> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 3e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;
LL BIT[SIZE];
void add(int x,int t){
  x++;
  while(x<=SIZE){
    BIT[x]+=t;
    x+=x&-x;
  }
}
LL sum(int x){
  x++;
  int ans=0;
  while(x>0){
    ans+=BIT[x];
    x-=x&-x;
  }
  return ans;
}
LL sum(int a,int b){
  return sum(b)-sum(a-1);
}
LL P[SIZE];
LL solve(){

 	LL N,K;
  cin >> N >> K;
  REP(i,N){
    cin >> P[i];
    add(i+1,1);
  }
  
  if(K==N){
    REP(i,N-1)
      if(P[i]%N!=(P[i+1]+N-1)%N) return 0;
    return 1;
  }
  if(K%2==0) return 1;
  LL ans=0;
  REP(i,N){
    ans+=sum(1,P[i]-1);
    add(P[i],-1);
  }
  if(ans%2) return 0;
  return 1;
}
signed main(){
  YesNo;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4684
final_rank: 13