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 ...
随机推荐
- linux内存管理源码分析 - 页框分配器
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 最近在学习内核模块的框架,这里做个总结,知识太多了. 分段和分页 先看一幅图 也就是我们实际中编码时遇到的内存地 ...
- c# 设置桌面背景窗口 SetParent
using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms ...
- Spring Boot(十六):使用 Jenkins 部署 Spring Boot
Jenkins 是 Devops 神器,本篇文章介绍如何安装和使用 Jenkins 部署 Spring Boot 项目 Jenkins 搭建.部署分为四个步骤: 第一步,Jenkins 安装 第二步, ...
- TRIO-basic指令--九九乘法表demo
在路上闲的没事,想到之前自己用别的语言实现乘法口诀表,于是来了兴趣用TRIO-basic试一下,挺简单的一段代码,大家看看就好. ' TRIO-basic '实现乘法口诀表 定义两个整型的局部变量 D ...
- 基于 CentOS 搭建 FTP 文件服务
https://www.linuxidc.com/Linux/2017-11/148518.htm
- 总结and规划
不知不觉中又过去了一年,马上就要读研究生了,因此有必要对自己进行必要的总结,以及对自己有个良好的规划. 首先,描述自己当前的心情——对未来充满了恐惧和焦虑. 马上大学就要毕业了,回首经历的大学生涯,似 ...
- “Linux内核分析”第五周报告
张文俊+ 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 学习总结 1.给M ...
- Linux实验四报告
张文俊 + 原创作品转载请注明出处+ <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.学习内容 系统 ...
- 数据结构--图 的JAVA实现(下)
在上一篇文章中记录了如何实现图的邻接表.本文借助上一篇文章实现的邻接表来表示一个有向无环图. 1,概述 图的实现与邻接表的实现最大的不同就是,图的实现需要定义一个数据结构来存储所有的顶点以及能够对图进 ...
- JS对象复制(深拷贝、浅拷贝)
如何在 JS 中复制对象 在本文中,我们将从浅拷贝(shallow copy)和深拷贝(deep copy)两个方面,介绍多种 JS 中复制对象的方法. 在开始之前,有一些基础知识值得一提:Javas ...