Program Optimization

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

Consider the following C++ code:

#include <algorithm>
#include <random>

int query_mex(const int *a, int l, int r);

int simulate(int n, int *a, int q, int k, int s) {
  std::mt19937 gen;
  gen.seed(s);
  int last = 0;
  while (q--) {
    int op = gen() % k;
    int i = (gen() + last) % n;
    if (!op && i) {
      std::swap(a[i - 1], a[i]);
    } else {
      int j = gen() % n;
      last ^= query_mex(a, std::min(i, j), std::max(i, j));
    }
  }
  return last;
}

In the program, query_mex(a, l, r) returns the minimum non-negative integers which does not occur in a_l,a_l+1,,a_ra\_l, a\_{l + 1}, \dots, a\_{r}.

Given the value of nn, aa, qq, kk and ss, find the returned value of the function.

입력

The first line contains four integers nn, qq, kk and ss (1n2×1051 \leq n \leq 2\times 10^5, 1q1071 \leq q \leq 10^7, 1k1091 \leq k \leq 10^9, 0s1090 \leq s \leq 10^9). The second line contains nn distinct integers a_0,a_1,,a_n1a\_0, a\_1, \dots, a\_{n - 1} (0a_i<n0 \leq a\_i < n).

출력

Output an integer denoting the returned value.