codeforces 777C
C.Alyona and Spreadsheet
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 mcolumns. 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 ifai, 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 rinclusive 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 alli 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 lito ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
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
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.
解题思路:
这道题有很多种其中用二维数组做耗时比较少,只需注意一下,先输入m和n,在确定数组范围就行
由于被zz队友演了一波跟我说不能用二维数组,然后我就用一维数组直接递推了,差别不大
题意是 求每个询问代表的l行到r行之间是否有至少一列非递减序列
核心思想就是由上往下推,得出每一行所能到达的最上层,并用数组储存起来,最后只需比较询问的r行的最上层是否<=l行
代码中a[]储存当前一行的数据,b[]储存当前每一列能到达的最上层的值,pre[]储存这一行所能到达的最上层也就b[]中值最小的;
实现代码:
#include <iostream>
using namespace std;
int n,m,a[],b[],pre[],x,l,r,i,j,k;
int main(){
cin>>n>>m;
for(i=;i<=n;i++){
pre[i]=i;
for(j=;j<=m;j++){
cin>>x;
if(x<a[j])
b[j]=i;
a[j]=x;
if(b[j]<pre[i])
pre[i]=b[j];
}
}
cin>>k;
while(k--){
cin>>l>>r;
if(pre[r]<=l)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
codeforces 777C的更多相关文章
- Codeforces 777C Alyona and Spreadsheet
		C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ... 
- Codeforces 777C - Alyona and Spreadsheet - [DP]
		题目链接:http://codeforces.com/problemset/problem/777/C 题意: 给定 $n \times m$ 的一个数字表格,给定 $k$ 次查询,要你回答是否存在某 ... 
- codeforces 777C.Alyona and Spreadsheet  解题报告
		题目链接:http://codeforces.com/problemset/problem/777/C 题目意思:给出一个 n * m 的矩阵,然后问 [l, r] 行之间是否存在至少一列是非递减序列 ... 
- 【codeforces 777C】 Alyona and Spreadsheet
		[题目链接]:http://codeforces.com/contest/777/problem/C [题意] 给你n行m列的矩阵: 然后给你k个询问[l,r]; 问你在第l到第r行,是否存在一个列, ... 
- Codeforces 777C:Alyona and Spreadsheet(思维)
		http://codeforces.com/problemset/problem/777/C 题意:给一个矩阵,对于每一列定义一个子序列使得mp[i][j] >= mp[i-1][j],即如果满 ... 
- Codeforces 777C Alyona and Spreadsheet(思维)
		题目链接 Alyona and Spreadsheet 记a[i][j]为读入的矩阵,c[i][j]为满足a[i][j],a[i - 1][j], a[i - 2][j],......,a[k][j] ... 
- Codeforces 777C:Alyona and Spreadsheet(预处理)
		During the lesson small girl Alyona works with one famous spreadsheet computer program and learns ho ... 
- python爬虫学习(5) —— 扒一下codeforces题面
		上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ... 
- 【Codeforces 738D】Sea Battle(贪心)
		http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ... 
随机推荐
- 1-微信小程序开发(安装软件和运行第一个微信小程序)
			https://developers.weixin.qq.com/miniprogram/dev/ 我的 打开 上传成功后 
- Maven-SSM项目pom.xml配置以及springmvc配置以及mybatis配置及web.xml配置
			一.Maven本地仓库的pom.xml配置 (全部是mysql数据库) <project xmlns="http://maven.apache.org/POM/4.0.0" ... 
- 在IIS上部署你的ASP.NET Core项目 (转载)
			概述 与ASP.NET时代不同,ASP.NET Core不再是由IIS工作进程(w3wp.exe)托管,而是使用自托管Web服务器(Kestrel)运行,IIS则是作为反向代理的角色转发请求到Kest ... 
- 安卓自动化测试,贺晓聪之uiautomator设备和选择器~Python详解
			1.设备对象 引入uiautomator,获取设备对象<所谓设备对象可理解为:Android模拟器或者真机> 语法:from uiautomator import device as d ... 
- 基于Angular+WebAPI+OData的增删改查
			对于在ASP.NET WebAPI中怎么使用OData,已经在我前面的日志中的说明, 在ASP.NET Web API中使用OData 在这个示例中.我新建了一个Order的实体,在前端使用Angul ... 
- C#使用FFMPEG推流,并且获取流保存在本地,随时取媒体进行播放!
			最近开发了基于C#的推流器一直不大理想,终于在不懈努力之后研究了一点成果,这边做个笔记:本文着重在于讲解下如何使用ffmpeg进行简单的推流,看似简单几行代码没有官方的文档很吃力.并获取流的源代码:如 ... 
- 在Ubuntu18.04下将应用程序添加到启动器
			# 在启动器里面给应用程序添加一个快捷方式 在linux(ubuntu)平台下,很多小伙伴发现,自己去官网下载解压的软件不能自动添加到启动器,每次启动的时候需要再次进入软件目录输入命令,非常不方便.本 ... 
- B. Vova and Trophies
			链接 [https://codeforces.com/contest/1082/problem/B] 题意 给你一个包含GS的字符串,只允许交换一次任意不同位置的字符,问最长的连续G串是多少 分析 很 ... 
- 第三周作业————————word count
			#include <stdio.h> void main() { FILE *fp; , str, word, pu, ch; int g; str = ; word = ; pu = ; ... 
- layui使用记录
			一.layui表格渲染 如果后台返回的实力类里面包含另一个实体类,那么需要使用如下方式取出相应的值 var tableResult = table.render({ elem: '#' + Serve ... 
