#P15940. [JOI Final 2026] 花园 3 / Garden 3

[JOI Final 2026] 花园 3 / Garden 3

Problem Description

The JOI-Garden has a rectangular shape divided into a grid of HH rows and WW columns. The cell in the ii-th row from the top and the jj-th column from the left is called cell (i,j)(i, j).

When rain falls on a cell, the moisture level of that cell increases. The moisture level of a cell never changes except when it rains. If the moisture level of a cell becomes at least XX, the cell turns into mud, which is dangerous. Therefore, every morning, JOI-kun, the manager of the JOI-Garden, may designate at most one rectangular off-limits area that contains all cells whose moisture level is at least XX. More precisely, JOI-kun chooses four integers u,d,l,ru,d,l,r (1udH1 \leq u \leq d \leq H, 1lrW1 \leq l \leq r \leq W), and the rectangular region consisting of all cells (i,j)(i, j) satisfying uidu \leq i \leq d and ljrl \leq j \leq r becomes off-limits.

Initially, the moisture level of every cell in the JOI Garden is 00.

Starting today, it will rain once every evening for NN days. On the evening of the (k1)(k-1)-th day after (1kN1 \leq k \leq N), rain falls on every cell (i,j)(i, j) satisfying UkiDkU_k \leq i \leq D_k and LkjRkL_k \leq j \leq R_k, and the moisture level of each such cell increases by CkC_k.

For each k=1,2,,Nk=1,2,\dots,N, write a program that computes the minimum possible number of cells contained in the off-limits area that JOI-kun sets on the morning of the kk-th day after.

Input Format

Read the following data from the standard input.

HH WW NN XX
U1U_1 D1D_1 L1L_1 R1R_1 C1C_1
U2U_2 D2D_2 L2L_2 R2R_2 C2C_2
\vdots
UNU_N DND_N LNL_N RNR_N CNC_N

Output Format

Write NN lines to the standard output. The kk-th line (1kN1 \leq k \leq N) of the output should contain the minimum possible number of cells contained in the off-limits area that JOI-kun sets on the morning of day kk.

3 3 5 10
3 3 1 1 5
1 3 1 2 7
1 3 3 3 4
1 1 1 2 12
3 3 3 3 6
0
1
1
6
9
9 1 5 1
3 3 1 1 4
5 8 1 1 1
3 5 1 1 3
8 8 1 1 4
8 9 1 1 5
1
6
6
6
7
4596 9794 15 141929907
600 3070 2222 8763 472026497
47 2644 3276 6033 930213777
638 945 304 1100 992702990
370 2211 2178 2977 783902937
277 2601 1559 8989 842013671
566 3272 3124 8456 254633541
91 4241 2655 8035 303526265
1342 3662 3909 7175 685435928
1176 4012 2827 8429 614977118
255 2461 1482 5835 794902067
982 2314 941 3952 342731056
1603 2215 6730 7105 332440107
2301 4568 6898 9561 591652619
124 2097 3520 8882 168525684
1845 3599 5592 7145 555656973
16165282
19783008
25583040
25583040
26266464
28021036
36437770
36437770
36437770
36437770
36437770
36437770
41864676
41864676
41864676

Hint

Sample 1

The following is one example of how the moisture levels increase each day and how the off-limits area can be chosen so that the number of contained cells is minimized.

  • On the evening of day 00, the moisture level of cell (3,1)(3,1) increases by 55. On the morning of day 11, there are no cells whose moisture level of at least 1010, so no off-limits area is set.
  • On the evening of day 11, the moisture level of cells (1,1)(1,1), (1,2)(1,2), (2,1)(2,1), (2,2)(2,2), (3,1)(3,1), and (3,2)(3,2) each increase by 77. On the morning of day 22, cell (3,1)(3,1) has moisture level of at least 1010. JOI-kun chooses u=d=3u = d = 3 and l=r=1l = r = 1, thereby setting a off-limits area that contains 11 cell.
  • On the evening of day 22, the moisture level of cells (1,3)(1,3), (2,3)(2,3), and (3,3)(3,3) each increase by 44. On the morning of day 33, cell (3,1)(3,1) has moisture level of at least 1010. JOI-kun chooses u=d=3u = d = 3 and l=r=1l = r = 1, thereby setting a off-limits area that contains 11 cell.
  • On the evening of day 33, the moisture level of cells (1,1)(1,1), and (1,2)(1,2) each increase by 1212. On the morning of day 44, cells (1,1)(1,1),(1,2)(1,2), and (3,1)(3,1) has moisture level of at least 1010. JOI-kun chooses u=1u = 1, d=3d = 3, l=1l = 1, r=2r = 2, thereby setting a off-limits area that contains 66 cells.
  • On the evening of day 44, the moisture level of cell (3,3)(3,3) increases by 66. On the morning of day 55, cells (1,1)(1,1), (1,2)(1,2), (3,1)(3,1), and (3,3)(3,3) has moisture level of at least 1010. JOI-kun chooses u=1u = 1, d=3d = 3, l=1l = 1, r=3r = 3, thereby setting a off-limits area that contains 99 cells.

This sample input satisfies the constraints of Subtasks 3,43,4, and 55.

Sample 2

This sample input satisfies the constraints of all the subtasks.

Sample 3

This sample input satisfies the constraints of Subtasks 3,43,4, and 55.

Constraints

  • 1H1091 \leq H \leq 10^{9}.
  • 1W1091 \leq W \leq 10^{9}.
  • 1N2000001 \leq N \leq 200000.
  • 1X2×10141 \leq X \leq 2 \times 10^{14}.
  • 1UkDkH1 \leq U_k \leq D_k \leq H (1kN1 \leq k \leq N).
  • 1LkRkW1 \leq L_k \leq R_k \leq W (1kN1 \leq k \leq N).
  • 1Ck1091 \leq C_k \leq 10^{9} (1kN1 \leq k \leq N).
  • Given values are all integers.

Subtasks

  1. (33 points) X=1X = 1.
  2. (2424 points) W=1W = 1.
  3. (1515 points) N300N \leq 300.
  4. (3030 points) N5000N \leq 5000.
  5. (2828 points) No additional constraints.