Codeforces 777C - Alyona and Spreadsheet - [DP]
题目链接:http://codeforces.com/problemset/problem/777/C
题意:
给定 $n \times m$ 的一个数字表格,给定 $k$ 次查询,要你回答是否存在某一列 $j$,其对应于询问区间 $[l,r]$ 的 $a[l][j], a[l+1][j], \cdots, a[r][j]$ 这个序列,是否为非递减的。
题解:
考虑 $f[i][j]$ 表示只考虑第 $j$ 列的情况下,以 $a[i][j]$ 为末尾的单调不减序列的最长长度,这个很容易求出来。
那么,我们对于某一行 $i$,已经可以知道 $f[i][1],f[i][2], \cdots, f[i][m]$ 这些值了,求出它们的最大值 $mx[i]$,这个值即对应一个查询 $[l,r]$,在确定下端为 $r$ 的情况下,其上端最长可以延伸多远。
时间复杂度为 $O(nm+k)$。
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int SIZE=1e5+;
int n,m,q;
int a[SIZE],f[SIZE],mx[SIZE];
inline idx(int x,int y){return x*m+y;}
inline x(int idx){return idx/m;}
inline y(int idx){return idx%m;}
int main()
{
ios::sync_with_stdio();
cin.tie(), cout.tie(); cin>>n>>m;
for(int i=;i<n;i++)
{
mx[i]=;
for(int j=;j<m;j++)
{
cin>>a[idx(i,j)]; if(i== || a[idx(i-,j)]>a[idx(i,j)]) f[idx(i,j)]=;
else f[idx(i,j)]=f[idx(i-,j)]+; mx[i]=max(mx[i],f[idx(i,j)]);
}
} cin>>q;
int l,r;
while(q--)
{
cin>>l>>r; l--,r--;
if(mx[r]>=r-l+) cout<<"Yes\n";
else cout<<"No\n";
}
}
Codeforces 777C - Alyona and Spreadsheet - [DP]的更多相关文章
- 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(思维)
题目链接 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 解题报告
题目链接:http://codeforces.com/problemset/problem/777/C 题目意思:给出一个 n * m 的矩阵,然后问 [l, r] 行之间是否存在至少一列是非递减序列 ...
- Codeforces Round #401 (Div. 2) C Alyona and Spreadsheet —— 打表
题目链接:http://codeforces.com/contest/777/problem/C C. Alyona and Spreadsheet time limit per test 1 sec ...
- C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)
Alyona and Spreadsheet 这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢? [题目链接]Alyona and Spre ...
- Codeforces777C Alyona and Spreadsheet 2017-05-04 17:46 103人阅读 评论(0) 收藏
C. Alyona and Spreadsheet time limit per test 1 second memory limit per test 256 megabytes input sta ...
- codeforces 777C
C.Alyona and Spreadsheet During the lesson small girl Alyona works with one famous spreadsheet compu ...
- Codeforces E. Alyona and a tree(二分树上差分)
题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)
[BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ...
随机推荐
- fft ocean注解
针对这两篇教程: http://www.keithlantz.net/2011/10/ocean-simulation-part-one-using-the-discrete-fourier-tran ...
- Atitit 大json文件的结构化查看解决方案,高性能的jsonview attilax总结.docx
Atitit 大json文件的结构化查看解决方案,高性能的jsonview attilax总结.docx 1.1. 实现目标:1 1.2. 实现key与value类型的..一直分析到非 jsonob ...
- IOS开发 文件路径
1.开发平台路径: /Developer/Platforms 此路径下一般有三个目录,分别是mac电脑.模拟器.iphone真机 MacOSX.platform iPhoneSimulator.pla ...
- [k8s]kube-dns/dashboard排错历险记(含sa加载用法/集群搭建)
kube-dns原理 参考: 组件架构看这个就够了 http://cizixs.com/2017/04/11/kubernetes-intro-kube-dns 设置细节看这个就够了 http://b ...
- TypeScript学习笔记(九):装饰器(Decorators)
装饰器简介 装饰器(Decorators)为我们在类的声明及成员上通过元编程语法添加标注提供了一种方式. 需要注意的是:装饰器是一项实验性特性,在未来的版本中可能会发生改变. 若要启用实验性的装饰器特 ...
- Source Insight 4.0常用设置
本文以Source Insight 4.00.0086版本为例讲解常用设置. 1.Source Insight简介 Source Insight是一个面向软件开发的代码编辑器和浏览器,它拥有内置的对C ...
- 【Android】Eclipse性能优化,快捷方式,文档注释
快捷方式 方法注释的快捷键:ALT + SHIFT +J 格式化:Ctrl+Shift+F 把当前选中的文本全部变味大写:Ctrl+Shift+X 把当前选中的文本全部变为小写:Ctrl+Shift+ ...
- json简介及JsonCpp用法
[时间:2017-04] [状态:Open] [关键词:数据交换格式,json,jsoncpp,c++,json解析,OpenSource] json简介 本文仅仅是添加我个人对json格式的理解,更 ...
- servlet中web.xml配置详解
Web.xml常用元素 <web-app> 所有部署描述符文件的顶层(根)元素 <display-name></display-name>定义了WEB应用的名字 & ...
- centos 扩容
1. 查看挂载点信息: [root@localhost]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 18G 15G 2.9G 84% / ...