luogu#P9631. [ICPC2020 Nanjing R] Just Another Game of Stones

[ICPC2020 Nanjing R] Just Another Game of Stones

题目描述

Kotori and Umi are playing games of stones, which is hosted by Honoka. The rule is the same as the classic one: There are some piles of stones and the players take turns to remove any positive number of stones from one pile. The one who can't make a legal move loses the game.

This time however, things will be a little different. As the host, Honoka will prepare the games from nn candidate piles of stones, where the ii-th pile initially has aia_i stones. Honoka will perform qq operations of the following two types:

  • Given three integers ll, rr and xx, for all lirl \le i \le r change the number of stones in the ii-th candidate pile to max(bi,x)\max(b_i, x), where bib_i is the current number of stones in the ii-th candidate pile.
  • Given three integers ll, rr and xx, start a game of stones consisting of (rl+2)(r-l+2) piles where the ii-th pile contains bl1+ib_{l-1+i} stones for all 1i<(rl+2)1 \le i < (r-l+2), and the (rl+2)(r-l+2)-th pile contains xx stones. Note that this operation is only querying for answer and will not affect the state of the nn candidate piles of stones.

Kotori is always the first to move. As a big fan of Kotori, you would like to know, for each game of stones, the number of ways Kotori can play in the first step to ensure her victory if both players use the best strategy. We consider two ways different if Kotori is taking stones from different piles, or from the same pile but is taking different number of stones.

输入格式

There is only one test case in each test file.

The first line of the input contains two integers nn and qq (1n,q2×1051 \le n, q \le 2 \times 10^5) indicating the number of candidate piles and the number of operations.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n (0ai23010 \le a_i \le 2^{30}-1) where aia_i indicates the initial number of stones in the ii-th pile.

For the following qq lines, the ii-th line contains four integers opiop_i, lil_i, rir_i and xix_i (opi{1,2}op_i \in \{1, 2\}, 1lirin1 \le l_i \le r_i \le n, 0xi23010 \le x_i \le 2^{30}-1) indicating the ii-th operation, where opiop_i is the type of operation and the others are the parameters of the operation. Operations are given in the order they're performed.

输出格式

For each operation of the second type output one line containing one integer indicating the answer.

题目大意

给定 nn 个石堆,第 ii 个石堆的石子数为 aia_i,有 qq 次操作:

1 l r x 表示将所有满足 lirl \leq i \leq raia_i 赋值为 max(ai,x)\max(a_i,x)

2 l r x 表示用石堆 [l,r][l,r] 和一个石子数为 xx 的石堆进行 Nim 游戏,求出第一次先手取完石子后游戏变为后手必败局面的可操作总方案数。

(如果你还不了解 Nim 游戏,点这里)。

对于 100%100\% 的数据保证 1q,n2×1051 \le q,n \le 2 \times 10^50ai,xi23010 \le a_i,x_i \le 2^{30}-1op{1,2}op \in \{1,2\}1li,rin1 \le l_i,r_i \le n

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

提示

For the first operation the players will play a game of stones consisting of 11, 22, 11 and 11 stone(s) in each pile respectively. The only winning play for Kotori is reduce the pile with 22 stones to 11 stone.

After the second operation, number of stones in the candidate piles changes to 11, 33, 33, 44 and 11 respectively.

For the fourth operation the players will play a game of stones consisting of 11, 33, 33, 44 and 44 stone(s) in each pile respectively. The winning plays for Kotori is to reduce the pile with 11 stone to 00 stone, or to reduce any pile with 33 stones to 22 stones.