#P11283. 「GFOI Round 2」Turtle and Nediam

    ID: 10337 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>洛谷原创O2优化洛谷月赛单调栈

「GFOI Round 2」Turtle and Nediam

Description

For a sequence aa of distinct positive integers with length a3|a| \geq 3, the "nediam" f(a)f(a) is defined as follows:

  • When a=3|a| = 3, f(a)f(a) is the median of aa;
  • When a>3|a| > 3, for any contiguous subsequence of length 33 denoted as [ai,ai+1,ai+2][a_i, a_{i + 1}, a_{i + 2}], let the median of this subsequence be xx. The sequence obtained by removing xx from aa is denoted as bb, and f(a)f(a) is the maximum value of f(b)f(b) over all such subsequences.

Turtle gives you a permutation p1,p2,,pnp_1, p_2, \ldots, p_n of the integers from 11 to nn and mm queries. For each query, given ll and rr, you need to calculate the "nediam" f([pl,pl+1,,pr])f([p_l, p_{l + 1}, \ldots, p_r]).

Input Format

To speed up the input process, we will use the following method.

The first line contains six positive integers n,m,seed,A,B,Cn, m, seed, A, B, C.

The second line contains a permutation p1,p2,,pnp_1, p_2, \ldots, p_n.

For the next mm queries, you will generate the pair (l,r)(l, r) as follows:

unsigned seed, A, B, C;

inline unsigned rnd() {
	seed = A * seed * seed + B * seed + C;
	seed = seed ^ (seed << 27);
	seed = seed ^ (seed >> 19);
	return seed;
}

inline std::pair<int, int> gen() {
	int l, r;
	do {
		l = rnd() % n + 1;
		r = rnd() % n + 1;
	} while (abs(l - r) < 2);
	if (l > r) {
		std::swap(l, r);
	}
	return std::make_pair(l, r);
}

For each query, call gen() once to generate the pair (l,r)(l, r) for that query.

Output Format

To speed up the output process, we will use the following method.

Let the answer for the ii-th query be ansians_i. You need to output $(1 \times ans_1) \oplus (2 \times ans_2) \oplus \cdots \oplus (m \times ans_m)$, where \oplus denotes the bitwise XOR operation.

4 4 114 514 1919 810
1 3 4 2

1

10 100 123456 789123 456789 123456789
3 9 5 7 6 4 10 8 2 1

142

Hint

Sample 11 Explanation

The generated four queries are (1,4),(1,3),(1,3),(2,4)(1, 4), (1, 3), (1, 3), (2, 4), with answers 2,3,3,32, 3, 3, 3 respectively. Therefore, you need to output $(1 \times 2) \oplus (2 \times 3) \oplus (3 \times 3) \oplus (4 \times 3) = 2 \oplus 6 \oplus 9 \oplus 12 = 1$.

For the first query, choosing the contiguous subsequence [1,3,4][1, 3, 4] or [3,4,2][3, 4, 2] will result in the deletion of 33. After removing 33, the remaining sequence is [1,4,2][1, 4, 2], and the median is 22.

Subtasks and Constraints

Subtask ID nn \le mm \le Special Properties Score
11 1818 100100 No 99
22 10610^6 5×1065 \times 10^6 A 55
33 10310^3 10410^4 No 1919
44 10510^5 1717
55 10610^6 10610^6 B 1515
66 No 1313
77 5×1065 \times 10^6 2222
  • Special Property A: pi=ip_i = i.
  • Special Property B: pp is randomly generated with equal probability from all permutations of 1n1 \sim n.

For all tests, it is guaranteed that:

  • 3n1063 \le n \le 10^6;
  • 1m5×1061 \le m \le 5 \times 10^6;
  • 0seed,A,B,C<2320 \le seed, A, B, C < 2^{32};
  • pp is a permutation of 1n1 \sim n.