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.


——————————————————————————————————————
题目的意思是给出有个矩阵,给出k组查询,询问每一列中是否存在第l行到第r行满足非递减的序列。
思路:从最后一行开始到第一行dp记录每一个能最大到达的列,再把一行的最大值取出来,查询是只要比较l行的最大值和r的关系即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f vector<int>v[100005];
vector<int>mp[100005];
int ans[100005]; int main()
{
int n,m,k,l,r,x;
while(~scanf("%d%d",&n,&m))
{ for(int i=1; i<=n; i++)
for(int j=0; j<m; j++)
{
scanf("%d",&x);
mp[i].push_back(x);
}
memset(ans,-1, sizeof ans);
for(int i=0; i<m; i++)
{
v[n].push_back(n);
}
ans[n]=n;
for(int i=n-1; i>=1; i--)
{
for(int j=0; j<m; j++)
{
if(mp[i][j]>mp[i+1][j])
v[i].push_back(i);
else
v[i].push_back(v[i+1][j]);
ans[i]=max(ans[i],v[i][j]);
} } scanf("%d",&k);
for(int i=0; i<k; i++)
{
scanf("%d%d",&l,&r); if(ans[l]<r)
printf("No\n");
else
printf("Yes\n");
}
}
return 0;
}

Codeforces777C Alyona and Spreadsheet 2017-05-04 17:46 103人阅读 评论(0) 收藏的更多相关文章

  1. jQuery easyUI datagrid 增加求和统计行 分类: JavaScript 2015-01-14 17:46 2178人阅读 评论(0) 收藏

    在datagrid的onLoadSuccess事件增加代码处理. <style type="text/css"> .subtotal { font-weight: bo ...

  2. 团体程序设计天梯赛L1-020 帅到没朋友 2017-03-22 17:46 72人阅读 评论(0) 收藏

    L1-020. 帅到没朋友 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为 ...

  3. Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏

    在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...

  4. The 3n + 1 problem 分类: POJ 2015-06-12 17:50 11人阅读 评论(0) 收藏

    The 3n + 1 problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53927   Accepted: 17 ...

  5. Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏

    胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Subm ...

  6. ubuntu中安装jdk 分类: java 学习笔记 linux ubuntu 2015-07-06 17:49 74人阅读 评论(0) 收藏

    参考文献:ubuntu 13.04 安装 JDK 先去oracle官网下载jdk,这一段我就不赘述了. 下载好之后先解压,解压方式参见 linux常用的压缩与解压缩命令 ,解压之后,将文件剪贴至/us ...

  7. APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏

    APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...

  8. POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13598   Accepted: 5791 ...

  9. Hdu428 漫步校园 2017-01-18 17:43 88人阅读 评论(0) 收藏

    漫步校园 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissi ...

随机推荐

  1. 趣味编程:静夜思(JOOL版)

    JOOL <dependency> <groupId>org.jooq</groupId> <artifactId>jool</artifactI ...

  2. Session的作用和使用场景

    1.session何时被创建? 客户首次访问服务器时,回话session对象被创建并分配一个唯一的Id,同时id号发送到客户端,并存入cookie,使得客户端session对象和服务器端一致. 2.如 ...

  3. MVC3 发布到IIS 7.5

    1.应用程序池采用集成模式(建议),.NET Framework版本为: .NET Framework4.0.30319. 2.确保ASP.NET MVC3已安装好,然后检查站点的处理程序映射,看是否 ...

  4. AUC理解

    https://www.zhihu.com/question/39840928 机器学习和统计里面的auc怎么理解?

  5. AnimatorOverrideController

    [AnimatorOverrideController] 有N个角色,这N个角色的状态机一样,只是动画不一样.这时候,新建一个AnimatorController,设置状态机.然后为这N个角色建立N个 ...

  6. mysql服务器设置其他电脑访问

    解决pc.b想访问pc.a上的mysql而访问不了的问题. 第一步:先在navicat的tools里面选择console 第二步:输入下面的信息: '; 其中wp是登陆数据库的用户名,IP地址是允许访 ...

  7. Linux找不到动态库

    首先系统上得有,只是路径问题 可使用ldd查看可执行程序的依赖库 以下都需要超级权限: find / -name libnet.so.9 // 可能在/usr/lib或/usr/local/lib中 ...

  8. java和数据结构的面试考点

    目标:不要有主要的逻辑错误.2遍以内bug free.注意代码风格 不要让面试官觉得不懂规矩 Java vs C++ Abstract class vs interface  pass by refe ...

  9. .NET格式化字符串详细说明

    DataFormatString属性:{0:Bxx}B为取值类型 C 以货币格式显示数值. D 以十进制格式显示数值. E 以科学记数法(指数)格式显示数值. F 以固定格式显示数值. G 以常规格式 ...

  10. struts框架之总结OGNL表达式的特殊的符号

    1. # 符号的用法 * 获得contextMap中的数据 > <s:property value="#request.name"/> > <s:pr ...