CF777C.Alyona and Spreadsheet
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By a__i, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if a__i, j ≤ a__i + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that a__i, j ≤ a__i + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
在课堂上,小女孩阿廖娜正在使用一款著名的电子表格程序,并学习如何编辑表格。
现在她有一个填满整数的表格。该表格共有 n 行和 m 列。用 ai,j 表示位于第 i 行、第 j 列的整数。我们称表格在第 j 列中按非递减顺序排列,当且仅当对所有 i(从 1 到 n−1),均有 ai,j≤ai+1,j。
老师给阿廖娜布置了 k 个任务。对每个任务,给出两个整数 l 和 r,阿廖娜需要回答如下问题:如果只保留第 l 行到第 r 行(含端点),而删除其余所有行,那么剩余的表格是否至少在某一列中按非递减顺序排列?形式化地说,是否存在某个列索引 j,使得对所有 i(从 l 到 r−1,含端点),均有 ai,j≤ai+1,j?
阿廖娜年纪太小,无法独立完成这项任务,请你帮帮她!
输入格式
The first line of the input contains two positive integers n and m (1 ≤ n·m ≤ 100 000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for a__i, j (1 ≤ a__i, j ≤ 109).
The next line of the input contains an integer k (1 ≤ k ≤ 100 000) — the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers l__i and r__i (1 ≤ l__i ≤ r__i ≤ n).
输入的第一行包含两个正整数 n 和 m(1≤n⋅m≤100000),分别表示表格的行数和列数。注意,题目给出的约束条件限制了这两个整数的乘积,即表格中元素的总数。
接下来的 n 行,每行包含 m 个整数。其中第 i 行的第 j 个整数表示 ai,j(1≤ai,j≤109)。
输入的下一行包含一个整数 k(1≤k≤100000),表示老师布置给 Alyona 的任务数量。
接下来的 k 行中,第 i 行包含两个整数 li 和 ri(1≤li≤ri≤n)。
输出格式
Print "Yes" to the i-th line of the output if the table consisting of rows from l__i to r__i inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
如果由第 li 行到第 ri 行(含)构成的子表在至少一列上按非递减顺序排列,则在输出的第 i 行打印“Yes”;否则打印“No”。
输入输出样例
输入#1
5 4 1 2 3 5 3 1 3 2 4 5 2 3 5 5 3 2 4 4 3 4 6 1 1 2 5 4 5 3 5 1 3 1 5
输出#1
Yes No Yes Yes Yes No
说明/提示
In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3.
在样例中,整个表格在任何一列上均未排序。然而,第 1–3 行在第 1 列上是有序的,而第 4–5 行在第 3 列上是有序的。
输入解题思路,AI测评打分。不知道怎么写?