#P7096. [yLOI2020] 泸沽寻梦

[yLOI2020] 泸沽寻梦

Description

To the south there is a land of immortals, called Mosuo; in Mosuo there is a lake, and it is Lugu.

Chacha is searching for her dream in Lugu Lake. In the hazy mist, Chacha’s nn dreams are arranged into a sequence. All of Chacha’s dreams look like “Lawa” (Lawa). To distinguish these Lawa, Chacha defines that the “beauty value” of the ii-th Lawa from left to right is a non-negative integer aia_i. Facing these dreams, Chacha will perform mm operations. Each operation gives two numbers p,xp, x, and then applies bitwise XOR with xx to both apa_p and ap+1a_{p+1}. After each operation, Chacha wants to know: in the current dream sequence, how many subsegments [l,r][l, r] satisfy lrl \le r and have XOR sum equal to 00. Please answer Chacha’s question.

The XOR sum of segment [l,r][l, r] is defined as $a_l \otimes a_{l + 1} \otimes \dots a_{r - 1} \otimes a_r$, where \otimes denotes the binary bitwise XOR operation, i.e. the “^” operator in C++. Two segments are different if and only if their left endpoints are different, or their right endpoints are different, or both are different.

To avoid overly large output, you only need to output four integers: the bitwise XOR of all your answers, the number of times your answer is odd, the maximum among all your answers, and the minimum among all your answers.

Input Format

The first line contains two integers, representing the number of dreams nn and the number of operations mm.
The second line contains nn space-separated integers, where the ii-th integer is the beauty value aia_i of the ii-th Lawa.
The next mm lines each contain two integers, denoting the pp and xx of one operation in order.

Output Format

Output four lines, each containing one integer, in order: the bitwise XOR of all your answers, the number of times your answer is odd, the maximum among all your answers, and the minimum among all your answers.

5 3
1 2 3 4 5
1 3
2 3
3 3
3
3
3
1

Hint

Sample 1 Explanation

  • After the first operation, the sequence becomes 2,1,3,4,5{2,1,3,4,5}. There is exactly one segment [1,3][1,3] whose XOR sum is 00, so the answer for this query is 11.
  • After the second operation, the sequence becomes 2,2,0,4,5{2,2,0,4,5}. The segments [1,2][1,2], [1,3][1,3], and [3,3][3,3] have XOR sum 00, so the answer for this query is 33.
  • After the third operation, the sequence becomes 2,2,3,7,5{2,2,3,7,5}. There is exactly one segment [1,2][1,2] whose XOR sum is 00, so the answer for this query is 11. The XOR of all answers is 33. There are 33 times when the answer is odd. The maximum among all answers is 33, and the minimum is 11.

Constraints

This problem uses bundled subtasks, with 5 subtasks in total.

  • Subtask 11 (1010 points): n,m100n, m \le 100.
  • Subtask 22 (1010 points): n,m300n, m \le 300.
  • Subtask 33 (2020 points): n,m3000n, m \le 3000.
  • Subtask 44 (3030 points): n,m105n, m \le 10^5.
  • Subtask 55 (3030 points): no special restrictions.

For the first four subtasks, it is guaranteed that ai,xna_i, x \le n.
For all testdata, it is guaranteed that 1n,m1061 \le n, m \le 10^6, 0ai,x1090 \le a_i, x \le 10^9, and 1p<n1 \le p < n.

Notes

  • Note that ai,xYa_i, x \leq Y does not imply aixYa_i \otimes x \leq Y.
  • Note the impact of large input size on program efficiency.
  • The special output format in this problem is only to avoid TLE due to overly large output, and is unrelated to the solution.
  • Note the impact of constant factors on program efficiency.
  • This problem provides two sample files; see dream.zip in the additional files.

Translated by ChatGPT 5