题目链接:http://codeforces.com/contest/777/problem/C

C. Alyona and Spreadsheet
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ai, 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 ai, j ≤ ai + 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 ai, j ≤ ai + 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!

Input

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 ai, j (1 ≤ ai, 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 li and ri (1 ≤ li ≤ ri ≤ n).

Output

Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".

Example
input
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

output
Yes
No
Yes
Yes
Yes
No

Note

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.


题解:

给出一个表格,给出l和r,问在l行和r行内(包括l行和r行),是否最少有一列,这列数随行数的递增,为非递减数列。

其中有k个l和r,k<=1000000, 情况这么大,每读入l r就对表格就行访问肯定会超时的,所以只能打表,读l r时直接访问。

其实怎么打表我是不会做的,所以还是看了通过的代码,发现他们都好聪明。

方法如下:用tt[j]现时记录在i行内,在aij以上(包括aij)有多少个非递减数列项,用maxn[i]记录在i行里tt[j]的最大值,即记录在i行内,哪一列的非递减数列项的个数最多。

于是在输入l r时,r-l+1即为需要判断的数列项个数, maxn[r]即为实际的数列项个数,如果maxn[r]>=r-l+1, 即表明l r行内存在非递减数列。

代码如下:

#include<stdio.h>
#include<cstring>
#define MAX(a,b) (a>b?a:b)
int main()
{  int n,m,k,l,r;  scanf("%d%d",&n,&m);  int a[n+5][m+5],maxn[n+5],tt[m+5];  memset(maxn,0,sizeof(maxn));  memset(tt,0,sizeof(tt));  for(int i = 0; i<n; i++)  for(int j = 0; j<m; j++)  {  scanf("%d",&a[i][j]);  if(i==0 || a[i][j]>=a[i-1][j]) tt[j]++;  else tt[j] = 1;  maxn[i] = MAX(maxn[i],tt[j]);  }  scanf("%d",&k);  for(int i = 0; i<k; i++)  {  scanf("%d%d",&l,&r);  if(r-l+1<=maxn[r-1]) puts("Yes");  else puts("No");  }  return 0;
} 

转载于:https://www.cnblogs.com/DOLFAMINGO/p/7538768.html

Codeforces Round #401 (Div. 2) C Alyona and Spreadsheet —— 打表相关推荐

  1. Codeforces Round #381 (Div. 1) A. Alyona and mex 构造

    传送门 文章目录 题意: 思路: 题意: 你需要确定一个长度为nnn的数组aaa,满足给定的mmm个[l,r][l,r][l,r]限制,需要保证构造出来的aaa数组对于每个[l,r][l,r][l,r ...

  2. Codeforces Round #736 (Div. 2) D. Integers Have Friends ST表gcd + 尺取

    传送门 文章目录 题意: 思路: 题意: 给你一个序列aaa,求一个最长的子序列[l,r][l,r][l,r]满足aimodm=ai+1modm=...=armodma_i\bmod m=a_{i+1 ...

  3. Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题

    A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...

  4. Codeforces Round #401 (Div. 2) E. Hanoi Factory 栈

    E. Hanoi Factory 链接: http://codeforces.com/contest/777/problem/E 题解: 排序b从小到大,在b相同排序a从小到大,使其满足如果i-1不能 ...

  5. Codeforces Round #401 (Div. 2) D Cloud of Hashtags —— 串

    题目链接:http://codeforces.com/contest/777/problem/D 题解: 题意:给出n行字符串,对其进行字典序剪辑.我自己的想法是正向剪辑的,即先对第一第二个字符串进行 ...

  6. Codeforces Round #401 (Div. 1) C(set+树状数组)

    题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...

  7. Codeforces Round #401 (Div. 2) D. Cloud of Hashtags

    题目链接:D. Cloud of Hashtags 题意: 给你n个字符串,让你删后缀,使得这些字符串按字典序排列,要求是删除的后缀最少 题解: 由于n比较大,我们可以将全部的字符串存在一个数组里面, ...

  8. Codeforces Round #401 (Div. 2) D. Cloud of Hashtags(字符串 + 逆向思维)

    D. Cloud of Hashtags 题意: 给你n个字符串,不能改变顺序,每个字符串可以选择从结尾删除连续的一段,使这n个字符串满足字典序从小到大的顺序.要求:删除的字符串尽量少. 题解: 最重 ...

  9. Codeforces Round #401 (Div. 2) D. Cloud of Hashtags(暴力)

    D. Cloud of Hashtags time limit per test2 seconds memory limit per test256 megabytes inputstandard i ...

最新文章

  1. c语言实现python列表_用C语言实现python的扩展模块
  2. mysql索引如何做_5分钟,告诉你MySQL字符串怎么做索引
  3. Flume学习笔记(一)安装与简单使用
  4. 最大正方形(洛谷-P1387)
  5. C#实现的UDP收发请求工具类实例
  6. mpython掌控板体温_用mpython x玩转掌控板——摇出好心情
  7. iPhone开发--NSDate操作(转)
  8. golang mac 环境变量_mac下配置go基本环境变量参数
  9. TeeChart.NET 4.2021.11.2 Crack
  10. c语言同构数循环,C语言求同构数.pdf
  11. tomcat日志配置-----自带log(一)
  12. 桃花、杏花、梨花、李花傻傻分不清?快来学习吧
  13. 听dalao讲课 7.26
  14. sql语句中count(*),count(1),count(id)区别详解
  15. WordPress模板教程
  16. Steam项目推进 (一) ——项目情况简述
  17. [生活] 领带的打法
  18. 基于 Spring Boot 的在线考试系统
  19. 导出CAD文件的几种方法
  20. Mockito之使用Answer

热门文章

  1. .NET Core中Quartz.NET的依赖注入
  2. JavaScript和Chrome中的SSDP发现
  3. mysql中表格 列变行_MySQL数据透视表的列数据作为行
  4. Django 报错 ‘polls‘ is not a registered namespace
  5. mac的python怎么输入中文_无法在python IDE(Mac OS X)中输入unicode
  6. 永恒python配合什么主武器_让Python代码更易维护的七种武器
  7. ibatis java配置文件,ibatis学习-sqlMap.xml配置文件 | 学步园
  8. linux 如何查看fb中分辨率_Ubuntu: Linux下查看本机显示器分辨率(xrandr)
  9. 谈谈你了解的python_你也可以侃侃而谈,一文带你了解Python的前世今生
  10. 怎么样才显示暗=安装好了mysql_linux mysql安装