codeforces 777C Alyona and Spreadsheet(预处理+思维)
来源:互联网 发布:国际阿里云注册 编辑:程序博客网 时间:2024/06/01 19:56
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 41 2 3 53 1 3 24 5 2 35 5 3 24 4 3 461 12 54 53 51 31 5
YesNoYesYesYesNo
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行,如果存在不递减的一列,则输出Yes。
这需要考虑每一列的问题,记录第i行的最大连续数,从c[i]表示到达第i行的最大不递减的数,然后对数组进行处理一下。
#include<cstdio>#include<vector>#include<cstring>#include<algorithm>using namespace std;vector<int>vec[100005];vector<long long>a[100005];int c[100005]; int main(){int n,m;long long ans;scanf("%d%d",&n,&m);for(int i=0;i<n;i++){int maxn=1;for(int j=0;j<m;j++){ scanf("%lld",&ans);a[i].push_back(ans);if(i==0||ans<a[i-1][j])//对数组进行处理,如果ans<a[i-1][j]成立,则重新从1开始{vec[i].push_back(1);} else{vec[i].push_back(vec[i-1][j]+1);maxn=max(maxn,vec[i][j]); }}c[i]=maxn;} int l,r,t;int flag;scanf("%d",&t);while(t--){ scanf("%d%d",&l,&r); if(r-l+1<=c[r-1]) printf("Yes\n"); else printf("No\n");} return 0;}
- codeforces 777C Alyona and Spreadsheet(预处理+思维)
- codeforces 777C Alyona and Spreadsheet(DP+思维)
- Codeforces 777C Alyona and Spreadsheet DP
- 【CodeForces 777C】Alyona and Spreadsheet
- 【codeforces 777C】 Alyona and Spreadsheet
- Codeforces 777C-Alyona and Spreadsheet
- 【Codeforces 777 C Alyona and Spreadsheet】
- codeforces 777C. Alyona and Spreadsheet (DP)
- CodeForces 777C Alyona and Spreadsheet
- Codeforces 777C Alyona and Spreadsheet
- Codeforces Round #401(Div. 2)C. Alyona and Spreadsheet【思维】
- (codeforces)C. Alyona and Spreadsheet
- codeforce 777 C. Alyona and Spreadsheet (打表预处理)
- 777C Alyona and Spreadsheet
- 777C Alyona and Spreadsheet
- Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet last数组、预处理、优化
- C. Alyona and Spreadsheet
- C. Alyona and Spreadsheet
- 算法竞赛入门经典 第二版 习题5-3 卡片游戏 Throwing cards away I uva10935
- 使用阿里的maven仓库
- 算法的时间复杂度
- Android存储
- Falcon(一)——数据集管理和数据处理平台
- codeforces 777C Alyona and Spreadsheet(预处理+思维)
- 92. Reverse Linked List II
- 为什么Java中1000==1000为false而100==100为true?
- IE\firfox\chrome的差异和兼容问题
- 像VS一样简单的打包“控制台”程序
- could not resolve host: github.com 问题解决办法
- springmvc入门
- 每天一题LeetCode[第十五天]
- Command python setup.py egg_info failed with error code 1