题目链接: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;
}

Codeforces Round #401 (Div. 2) C Alyona and Spreadsheet —— 打表的更多相关文章

  1. 【离线】【递推】【multiset】 Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet

    对询问按右端点排序,对每一列递推出包含当前行的单调不下降串最多向前延伸多少. 用multiset维护,取个最小值,看是否小于等于该询问的左端点. #include<cstdio> #inc ...

  2. Codeforces Round #401 (Div. 2) 离翻身就差2分钟

    Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35 ...

  3. C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)

    Alyona and Spreadsheet 这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢? [题目链接]Alyona and Spre ...

  4. Codeforces Round #401 (Div. 2)

    和FallDream dalao一起从学长那借了个小号打Div2,他切ABE我做CD,我这里就写下CD题解,剩下的戳这里 AC:All Rank:33 小号Rating:1539+217->17 ...

  5. Codeforces Round #401 (Div. 2) A,B,C,D,E

    A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...

  6. Codeforces Round #401 (Div. 2) A B C 水 贪心 dp

    A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...

  7. Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和

    B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...

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

    A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...

  9. Codeforces Round #381 (Div. 2) D. Alyona and a tree 树上二分+前缀和思想

    题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsm ...

随机推荐

  1. cocos2d-x step by step(3) Double Kill

    喏,咱们已经调通hello world 了,然后呢,咱们做一些高大上的东西,那做什么呢,做一个打乒乓球的小东西,啊哈! 这就是最终界面了,没画一个球形  就用一个白色方框代替吧. 啊哈! public ...

  2. C#使用反射机制获取类信息[转]

    http://www.cnblogs.com/zhoufoxcn/archive/2006/10/31/2515873.html 1.用反射动态创建类实例,并调用其公有成员函数. //新建一个类库项目 ...

  3. NFC模组,开发NFC功能 仅仅要几条指令的事情

    特点:实现NFC透明传输.内置NFC协议栈,支持UART串口直接读写,用于门禁能够同一时候兼容手机和卡片开门,还能实现动态密钥,读到的NFC数据自己主动串口输出,会串口就能开发NFC,不须要研究LLC ...

  4. 如何提高NodeJS程序的运行的稳定性

    如何提高NodeJS程序运行的稳定性 我们常通过node app.js方式运行nodejs程序,但总有一些异常或错误导致程序运行停止退出.如何保证node程序的稳定运行? 下面是一些可以考虑的方案: ...

  5. 手动安装pip

    apt-get instal pip  成功之后,有根据pip的提示,进行了升级,升级之后,pip就出问题了 为了解决上面问题,手动安装pip,依次执行下面命令 1 2 3 4 5 [root@min ...

  6. 基于ACCESS和ASP的SQL多个表查询与计算统计代码(一)

    近期在写几个关于"Project - Subitem - Task"的管理系统,说是系统还是有点夸大了,基本就是一个多表查询调用和insert.update的数据库操作.仅仅是出现 ...

  7. angular - 小结

    引入样式: 导入全局 - >styles.css 导入第三方 - > 在package.json配置,然后再 npm install 安装好以后,最后再angular.json里面的sty ...

  8. jquery easyui 全部图标

    所有的图标在 jquery-easyui-1.2.6\themes\icons 目录下, 在icon.css定义的如何引用 jquery-easyui-1.2.6/themes/icon.css .i ...

  9. AMD单双桥时序简叙

    芯片组(双桥)时序 VBAT :RTC电路的供电3V(RTC电路有问题会导致没复位或不跑码等故障) RTCCLK :晶振起振给南桥提供32.768KHz频率(RTC电路有问题会导致没复位或不跑码等故障 ...

  10. OI知识体系