#include #include #include #include #include #include #include #include using namespace std; using ll = long long; using ull = unsigned long long; ull seed; int next() { seed = seed ^ (seed << 13); seed = seed ^ (seed >> 7); seed = seed ^ (seed << 17); return (seed >> 33); } pair *pii; template void radix_sort(I first, I last) { using T = typename std::iterator_traits::value_type; constexpr int L = 16, M = 1 << L, K = 2; size_t n = last - first; T *p[2] = { &*first, pii }; size_t m[M]; std::fill_n(m, M, 0); for (size_t i = 0; i < n; i++) { m[(p[0][i].first & M - 1)]++; } for (int j = M - 1; j > 0; j--) { m[j] = m[j - 1]; } m[0] = 0; for (int j = 2; j < M; j++) { m[j] += m[j - 1]; } for (size_t i = 0; i < n; i++) { T t = p[0][i]; p[1][m[t.first & M - 1]++] = t; } std::swap(p[0], p[1]); std::fill_n(m, M, 0); for (size_t i = 0; i < n; i++) { m[(p[0][i].first >> L)]++; } for (int j = M - 1; j > 0; j--) { m[j] = m[j - 1]; } m[0] = 0; for (int j = 2; j < M; j++) { m[j] += m[j - 1]; } for (size_t i = 0; i < n; i++) { T t = p[0][i]; p[1][m[t.first >> L]++] = t; } std::swap(p[0], p[1]); } int main() { int n, q; cin >> n >> q >> seed; for (int i = 0; i < 10000; i++) { next(); } vector a(n); for (int i = 0; i < n; i++) { a[i] = next(); } sort(a.begin(), a.end()); ll r = 0; int q2 = q / 2; pii = (pair *)std::malloc(q2 * sizeof(pair)); vector> x(q2); for (int l = 0; l < 2; l++) { for (int h = 0; h < q2; h++) { x[h] = { next(), h + l * q2 }; } radix_sort(x.begin(), x.end()); ll k = 0; for (int h = 0; h < q2; h++) { while (k < n && a[k] < x[h].first) k++; r ^= k * x[h].second; } } cout << r << endl; return 0; }