codeforces 777C 想法题
来源:互联网 发布:淘宝店铺导航条全屏 编辑:程序博客网 时间:2024/05/11 01:48
Alyona and Spreadsheet
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 ≤
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.
题目链接
题意:给你一个n*m的矩阵,k个询问,每个询问有l,r,让你求在l-r行里面有没有一列可以满足从上到下为非递减数列。
解题思路:刚开始想到直接从下到上更新就好了,但是发现一个问题,n*m<=100000,那么n,m都有可能为100000,所以不能开二维数组更新,所以想到从上到下更新,然后用一个一维数组更新每行的数,用另一个一维数组更新这一行的每一列能到达的最上面的非递增数列,再用最后一个数组更新这一行能到达的最上面的非递增数列即可,然后在询问的时候就能用O(k)的时间算出答案了。
#include<cstdio>#define maxn 100005int a[maxn],b[maxn],c[maxn];int x,n,m,k,l,r;int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ c[i]=i; for(int j=1;j<=m;j++){ scanf("%d",&x); if(x<a[j]) b[j]=i; a[j]=x; if(b[j]<c[i]) c[i]=b[j]; } } scanf("%d",&k); while(k--){ scanf("%d%d",&l,&r); if(c[r]<=l) printf("Yes\n"); else printf("No\n"); } return 0;}
- codeforces 777C 想法题
- CodeForces 757 C 想法题
- Codeforces 229C Triangles 想法题
- Codeforces 229C 想法
- Codeforces 776C 想法
- Codeforces 796C 想法
- codeforces 3C Tic-tac-toe (想法题)
- codeforces #317 C. Lengthening Sticks (很好的想法题)
- codeforces 675C Money Transfers(想法题)
- codeforces round#347 div2 C International Olympiad 想法题
- Codeforces Round #377 (Div. 2)C. Sanatorium(想法题)
- codeForces 509E 想法题
- CodeForces 322D 想法题
- CodeForces 538B想法题
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples(构造题,想法题,好题)
- Codeforces Round #6——C. Alice, Bob and Chocolate(想法题)
- Pretty Song - CodeForces 509 E 想法题
- Codeforces 559B Equivalent Strings 想法题
- POJ 2125 Destroying The Graph 二分图 最小点权覆盖
- 注册Vultr购买VPS
- mysql 基本命令
- 串口通讯中断
- Linux:centos释放缓存,查看磁盘空间大小,xxx文件夹, 查看文件夹大小,查看剩余内存,查看xxx软件位置,统计某文件夹,统计某文件夹下目录数量,查看文件夹大小,给文件夹下所有的文件赋值权限
- codeforces 777C 想法题
- 并发1
- 蓝桥杯 基础练习 十六进制转十进制 java
- 打印机故障
- zeppelin的安装以及使用
- 找工作学习笔记2------阿里巴巴实习生笔试题(含答案)
- 进程间与线程间锁的方式与常用函数
- 【STM32】新手折腾笔记--03 系统级延时(Systick定时器)
- Python 字符串格式化