luogu#P5232. [JSOI2012] 智者的考验

[JSOI2012] 智者的考验

Problem Description

In the year 13711371 AD, the Founding Emperor ordered the construction of large temples on Beijige. In just a few years, ten temples were built on Jilong Mountain: the Imperial Temple, Guan Gong Temple, Zhenwu Temple, Merit Officials Temple, Jiang Wang Temple, Capital City God Temple, Bian Hu Temple, Martyrs Temple, King Liu Yue Temple, and King Cao Wuhui Temple. Together, they were called the “Ten Temples”.

Later, to make it easier for people to come to Jilong Mountain to burn incense and worship, the emperor ordered the clearing of the long-silted tidal ditch at the foot of Jilong Mountain. Thus, the “Incense River” came into being.

However, not everyone was allowed to go to Jilong Mountain. The emperor built a stone bridge over the Incense River, and in the middle hung a mechanism grid of height RxRx and width RyRy (as shown in the figure below). All cells can be flipped; one side is white and the other side is black. Here we use 00 to represent white and 11 to represent black. Initially, all cells show the white side. There are Rx+RyRx+Ry mechanism buttons corresponding to the RxRx rows and the RyRy columns. Once a button is triggered, the cells in the corresponding row or column are flipped simultaneously.

Meanwhile, the strategist Liu Ji, who was good at observing celestial phenomena, provided a black-and-white pattern called the “Misfortune Star”. Each person passing by and heading to Jilong Mountain must trigger exactly one button. After triggering, if the resulting pattern matches the “Misfortune Star”, the visitor is not allowed to pass.

The number of people coming to Jilong Mountain each day is known in advance and is NN. Also, since the empire’s power is overwhelming, each visitor at the beginning always has a high probability of triggering button number 11. We use a sequence A1,A2,,ANA_1, A_2, \dots, A_N to represent this, and it is guaranteed that initially all elements of AA are 11. Throughout the problem, AiA_i satisfies 1AiRx+Ry1 \leq A_i \leq Rx+Ry. The emperor cares a lot about how many people are not allowed to go to Jilong Mountain. So from time to time, he asks: “During a certain period of time, how many people cannot pass the ‘Misfortune Star’ trial?”. However, the scholars and poets coming to Jilong Mountain do not want such a single kind of operation. A visitor may suddenly decide to change the button they will trigger. In an even more troublesome case, several consecutive people traveling together may suddenly decide to change their buttons and all trigger the same button.

Now this troublesome problem is handed over to you.

Input Format

The first line contains two integers RxRx and RyRy, representing the height and width of the mechanism grid (as shown in the figure). Then follow RxRx lines, each containing RyRy digits, describing the “Misfortune Star” pattern. Each digit is either 00 or 11.

The next line contains two integers NN and MM, representing the number of people and the number of queries/modifications.

Then follow MM lines, each corresponding to one query or modification. Each line starts with an integer tt:

If tt is 00: then two integers dd and xx follow, meaning set AdA_d to xx.

If tt is 11: then two integers ll and rr follow, meaning query how many people from the ll-th to the rr-th person will produce the “Misfortune Star” pattern after triggering their button, and thus cannot pass.

If tt is 22: then three integers ll, rr, and xx follow, meaning set Al,Al+1,,Ar1,ArA_l, A_{l+1}, \dots, A_{r-1}, A_r all to xx.

Output Format

For each query (i.e., the case tt is 11), output a single line containing one integer, describing the number of people in the interval [l,r][l, r] that meet the requirement.

2 3 
0 0 1 
1 1 0 
7 4 
1 1 7 
0 2 3 
0 3 4	
1 1 7
0
3

Hint

For 40%40\% of the testdata, N5000N \leq 5000, M10000M \leq 10000.

For 70%70\% of the testdata, N130000N \leq 130000, M30000M \leq 30000.

For 100%100\% of the testdata, N1000000N \leq 1000000, M120000M \leq 120000, Rx2Rx \leq 2, Ry3Ry \leq 3.

Translated by ChatGPT 5