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中所有权 ...
随机推荐
- 【Android】详解Android Service
目录结构: contents structure [+] Service简单概述 Service在清单文件中的声明 Service启动服务 Service绑定服务 扩展Binder类 使用Messen ...
- SNF快速开发平台MVC-EasyUI3.9之-Session过期处理和页面请求筛选
Session引发的异常 其中一个bug是这样的: 使用Firefox登录进入系统后,再打开一个Tab,进入系统页面,点击logout. 在回到前一个tab页面,点击Save按钮,出现了js错误.这个 ...
- Ethereum for web developers
我学习以太坊区块链平台已经有一段时间了,这个真是让我越学越兴奋啊.网络上有很多关于以太坊的资料(文章,视频,平台官网),这些我们都很容易就获取到,由于平台还在快速迭代所以相关的资料内容普遍普遍滞后.自 ...
- Atitit.pagging 翻页功能解决方案专题 与 目录大纲 v3 r44.docx
Atitit.pagging 翻页功能解决方案专题 与 目录大纲 v3 r44.docx 1.1. 翻页的重要意义1 1.2. Dep废弃文档 paip.js翻页分页pageing组件.txt1 ...
- android源码 键盘消息处理机制
键盘消息处理模型: .WMS统一管理Window, 它包含了InputManager变量,其对应c++层的NativeInputManager2.c++层的NativeInputManager包含 i ...
- 【九天教您南方cass 9.1】 07 绘制与标注圆曲线和细部点的方法
同学们大家好,欢迎收看由老王测量上班记出品的cass9.1视频课程 我是本节课主讲老师九天. 我们讲课的教程附件也是共享的,请注意索取测量空间中. [点击索取cass教程]5元立得 (给客服说暗号:“ ...
- jsoup访问页面: PKIX path building failed
在用jsoup访问页面时报错javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX p ...
- react获取当前页面的url参数
react获取当前页面的url参数,必须在url路由对应的组件上获取,在子组件上获取不到,为undefined,获取形如 /news/:id 的后面的参数 id this.props.match. ...
- Python 函数(默认参数)
默认参数 设置默认参数时,有两点需要注意:一是必选参数在前,默认参数在后,否则python的解释器会报错二是当函数有多个参数时,把变化大的参数放前面,变化小的放后面,变化小的参数就可以作为默认参数 d ...
- 移除input在type="number"时的上下箭头
网页在有些情况下,会需要input的输入的为单纯数字的文本框,此时type=number,但使用type=number时,输入框后面会有一个上下箭头,那么如何去掉上下箭头呢? <input ty ...