Codeforces777C Alyona and Spreadsheet 2017-05-04 17:46 103人阅读 评论(0) 收藏
1 second
256 megabytes
standard input
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!
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).
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".
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
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.
#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) 收藏的更多相关文章
- jQuery easyUI datagrid 增加求和统计行 分类: JavaScript 2015-01-14 17:46 2178人阅读 评论(0) 收藏
在datagrid的onLoadSuccess事件增加代码处理. <style type="text/css"> .subtotal { font-weight: bo ...
- 团体程序设计天梯赛L1-020 帅到没朋友 2017-03-22 17:46 72人阅读 评论(0) 收藏
L1-020. 帅到没朋友 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为 ...
- Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏
在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...
- 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 ...
- 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 ...
- ubuntu中安装jdk 分类: java 学习笔记 linux ubuntu 2015-07-06 17:49 74人阅读 评论(0) 收藏
参考文献:ubuntu 13.04 安装 JDK 先去oracle官网下载jdk,这一段我就不赘述了. 下载好之后先解压,解压方式参见 linux常用的压缩与解压缩命令 ,解压之后,将文件剪贴至/us ...
- APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏
APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...
- POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 5791 ...
- Hdu428 漫步校园 2017-01-18 17:43 88人阅读 评论(0) 收藏
漫步校园 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
随机推荐
- js正则表达使用实例
(1)替换掉htmlStr中所有的<font..>和</font> var htmlstr='<font color="#fff">ABC< ...
- pandas 一行文本拆多行,一列拆多列
https://zhuanlan.zhihu.com/p/28337202 一列拆多列: http://blog.csdn.net/qq_22238533/article/details/761875 ...
- Containerpilot 配置文件示例
{ consul: "localhost:8500", logging: { level: "INFO", format: "default" ...
- 这两天的刷机+Root
最近为了研究Xposed框架的搭建使用,将自己红米Note2尝试root后,开不了机了.后使用(网上下载的线刷宝,刷的官网线刷宝成功开机了,然后里面会自带很多软件,然后通过下载KingRoot将手机自 ...
- lua 中的点、冒号与self
[lua 中的点.冒号与self] lua编程中,经常遇到函数的定义和调用,有时候用点号调用,有时候用冒号调用. girl = {money = 200} function girl.goToMark ...
- java rsa 加解密
参考 http://blog.csdn.net/a394268045/article/details/52232120 package rsa; import org.apache.commons.c ...
- <script language = "javascript">, <script type = "text/javascript">和<script language = "application/javascript">(转)
application/javascript是服务器端处理js文件的mime类型,text/javascript是浏览器处理js的mime类型,后者兼容性更好(虽然application/ ...
- javascript基础代码
1.点击改变HTML内容 <html> <head> <meta charset="UTF-8"> <script> functio ...
- 第五章 二叉树(b)树的表示
- suse11 sp4(虚拟机) 能ping通主机,但是主机ping不通suse虚拟机
sese的防火墙没关. 查看防火墙状态: rcSuSEfirewall2 status(必须是root账户,sudo都不行) 关闭防火墙:rcSuSEfirewall2 stop 事实上,防火墙有时候 ...