题目链接: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]的更多相关文章

  1. Codeforces 777C Alyona and Spreadsheet

    C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  2. 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] ...

  3. codeforces 777C.Alyona and Spreadsheet 解题报告

    题目链接:http://codeforces.com/problemset/problem/777/C 题目意思:给出一个 n * m 的矩阵,然后问 [l, r] 行之间是否存在至少一列是非递减序列 ...

  4. 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 ...

  5. C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)

    Alyona and Spreadsheet 这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢? [题目链接]Alyona and Spre ...

  6. 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 ...

  7. codeforces 777C

    C.Alyona and Spreadsheet During the lesson small girl Alyona works with one famous spreadsheet compu ...

  8. Codeforces E. Alyona and a tree(二分树上差分)

    题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)

    [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ...

随机推荐

  1. Visual Studio 统计代码行数

    介绍一种简单的统计代码行数的小技巧, 使用正则表达式,用VS强大的查找功能 b[^:b#/]+.$ 最后结果:

  2. Tomcat 七 HTTP 连接器

    摘要 本文尝试翻译Tomcat官方文档Apache Tomcat 7连接器,不足之处敬请指正.该文先介绍了Tomcat7 HTTP连接器的属性,包括:公共属性.标准实现.Java TCP套接字属性.B ...

  3. no accounts with itunes connect access

    有时候打包上传的时候 会遇见  no accounts with itunes connect access 的报错 原因主要如下: 1. 你没有被开发者管理员加入 itunes connect 权限 ...

  4. Swift 静态派发和动态派发

    前言 方法是 Swift 中的一个重要概念,方法允许你把需要复用的代码封装进方法中,这样当你调用方法时,实际上你的想法是执行方法中的那些代码,方法的出现极大的提高了方法的复用性. Swift 工程的环 ...

  5. php write_ini_file

    php读ini文件有很方便的pares_ini_file,但是写回去却没有,这里写一个: function write_ini_file($assoc_arr, $path, $has_section ...

  6. Nginx 介绍

    Nginx 是什么 Nginx ("engine x") 是一个开源的,支持高性能.高并发的 Web 服务和代理服务软件.它是由俄罗斯人 Igor Sysoev 开发的,最初被应用 ...

  7. JS中的PadLeft、PadRight,位数不足,自动补位,String扩展方法

    类似C#中的 PadLeft.PadRight方法 //方法一 function FillZero(p) { return new Array(3 - (p + '').length + 1).joi ...

  8. Asp.Net AutoMapper用法

    1.AutoMapper简介 用于两个对象映射,例如把Model的属性值赋值给View Model.传统写法会一个一个属性的映射很麻烦,使用AutoMapper两句代码搞定. 2.AutoMapper ...

  9. 【转】ubuntu16.04设置python3为默认及一些库的安装

    原文:https://www.cnblogs.com/jokie/p/6933546.html Ubuntu默认Python为2.7,所以安装Python包时安装的为py2的包. 利用alternat ...

  10. 【30集iCore3_ADP出厂源代码(ARM部分)讲解视频】30-5 底层驱动之旋转编码器

    源视频包下载地址:链接:http://pan.baidu.com/s/1mhENI9i密码:mf1x 银杏科技优酷视频发布区:http://i.youku.com/gingko8