#P2468. [SDOI2010] 粟粟的书架

    ID: 1479 远端评测题 3000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2010二分各省省选山东枚举,暴力主席树

[SDOI2010] 粟粟的书架

Description

Susu from Class B29 of Xingfu Kindergarten is a smart, obedient, and adorable child. Her hobbies are drawing and reading, and she especially likes the articles by Thomas H. Cormen. Susu’s home has a giant bookshelf with RR rows and CC columns, with one book at every position. The book at the ii-th row from the top and the jj-th column from the left has Pi,jP_{i,j} pages.

Besides reading, Susu has another essential daily task: picking apples. Each day she must pick a specific apple. The apples on her family’s trees are at various heights, and she cannot reach them on her own. However, she found that if she stands on some books, she can reach the apples. She also noticed that for the apple designated on day ii, as long as the total number of pages of the books under her feet is at least HiH_i, she will definitely be able to pick it.

Because there are too many books, her parents worry she might finish reading all of them in one day and be late for kindergarten, so each day they only allow her to take books from a specific region. This region is a rectangle: on day ii, the top-left corner is the book at row x1ix1_i and column y1iy1_i, and the bottom-right corner is the book at row x2ix2_i and column y2iy2_i. In other words, on that day, she can only select some books from these (x2ix1i+1)×(y2iy1i+1)(x2_i - x1_i + 1) \times (y2_i - y1_i + 1) books to stand on and pick the apple.

Each time Susu takes books, she returns them promptly to their original places, and the bookshelf will not have books removed or added. The apple-picking task continues for MM days. Given the number of pages of each book, the daily region restrictions, and the picking requirement, please tell Susu the minimum number of books she must take each day to pick the specified apple.

Input Format

The first line contains three positive integers R,C,MR, C, M.

Next is a matrix with RR rows and CC columns. From top to bottom and left to right, it gives the number of pages Pi,jP_{i,j} of each book.

Then follow MM lines. The ii-th line contains five positive integers x1i,y1i,x2i,y2i,Hix1_i, y1_i, x2_i, y2_i, H_i, meaning that on day ii the designated region is the rectangle between (x1i,y1i)(x1_i, y1_i) and (x2i,y2i)(x2_i, y2_i), and the required total number of pages is at least HiH_i.

It is guaranteed that 1x1ix2iR1 \le x1_i \le x2_i \le R and 1y1iy2iC1 \le y1_i \le y2_i \le C.

Output Format

Output MM lines. On the ii-th line, print the minimum number of books Susu needs on day ii to pick the apple. If she cannot pick the apple even by taking all books in the region, print Poor QLW.

5 5 7
14 15 9 26 53
58 9 7 9 32
38 46 26 43 38
32 7 9 50 28
8 41 9 7 17
1 2 5 3 139
3 1 5 5 399
3 3 4 5 91
4 1 4 1 33
1 3 5 4 185
3 3 4 3 23
3 1 3 3 108
6
15
2
Poor QLW
9
1
3
1 10 7
14 15 9 26 53 58 9 7 9 32
1 2 1 9 170
1 2 1 9 171
1 5 1 7 115
1 1 1 10 228
1 4 1 4 45704571
1 1 1 1 1
1 7 1 8 16
6
7
3
10
Poor QLW
1
2

Hint

For 10%10\% of the testdata, R,C10R, C \le 10.

For 20%20\% of the testdata, R,C40R, C \le 40.

For 50%50\% of the testdata, R,C200R, C \le 200, M2×105M \le 2 \times 10^5.

Additionally, for 50%50\% of the testdata, R=1R = 1, C5×105C \le 5 \times 10^5, M2×104M \le 2 \times 10^4.

For 100%100\% of the testdata, 1Pi,j10001 \le P_{i,j} \le 1000, 1Hi2×1091 \le H_i \le 2 \times 10^9.

Translated by ChatGPT 5