eolymp
bolt
Try our new interface for solving problems

Count

You have: \begin{itemize} \item A matrix of natural numbers, with the property that all rows and all columns are sorted in ascending order (i.e. \textbf{A\[i, j\]} ≥ \textbf{A\[i-1, j\]} and \textbf{A\[i, j\]} ≥ \textbf{A\[i, j-1\],} \includegraphics{https://static.e-olymp.com/content/a9/a95e3a2fa6a4bb21891b266af71619da5c09face.jpg} \textbf{i}, \textbf{j}) \item One or several pairs of numbers (\textbf{X}, \textbf{Y}) with the property that \textbf{Y} ≥ \textbf{X}. \end{itemize} For each (\textbf{X}, \textbf{Y}) pair, count how many numbers from the matrix are greater than or equal to \textbf{X} but smaller than or equal to \textbf{Y}. \InputFile The input file is a binary file containing \textbf{32}-bit integer numbers. The input file consists of: \begin{itemize} \item One integer \textbf{N} representing the number of rows (no more than \textbf{10000}) \item One integer \textbf{M} representing the number of columns (no more than \textbf{10000}) \item NxM integers, representing the values from the matrix, row by row \item An unspecified number of integers, representing the (\textbf{X}, \textbf{Y}) pairs, one pair at a time. There will be at least one pair and at most \textbf{100} pairs in the file -- and there will not be an incomplete pair at the end of the file. \end{itemize} \OutputFile For each pair you should write to standard output a value representing how many numbers in the matrix are greater than or equal to \textbf{X} but smaller than or equal to \textbf{Y}.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 512 MiB
Giriş verilənləri #1

Çıxış verilənləri #1
0
9
0
6
0
9
0
15
15
Mənbə ACM SEERC 2013, SouthEastern European Region, October, 12/10/2013, Vinnica & Bucharest