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中所有权 ...
随机推荐
- VirtualBox安装64位系统
2010-04-29 到引导区报错: This kernel requires an X86-64 CPU,but only detected an i686 CPU. 以我小学水平的英语理解 ...
- dup2替换
今天看APUE上一道题,要求不能用fcnt1来替换dup1. 刚开始的思路是dup一个,测试发现与期望的不一致就马上关闭,发现遇到无限循环,刚才想了下,才发现一旦close掉,再次dup仍然是分配最小 ...
- [转]MVC实用架构设计(三)——EF-Code First(3):使用T4模板生成相似代码
本文转自:http://www.cnblogs.com/guomingfeng/p/mvc-ef-t4.html 〇.目录 一.前言 二.工具准备 三.T4代码生成预热 (一) 单文件生成:Hello ...
- FTP上传、下载(简单小例子)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- HttpURLConnection与HttpClient比较和使用示例
1. GET请求与POST请求 HTTP协议是现在Internet上使用得最多.最重要的协议了,越来越多的Java应用程序需要直接通过HTTP协议来访问网络资源. 在介绍HttpURLConnecti ...
- [转]新人常识普及:我们为什么必须会git和maven
转自贴吧:http://tieba.baidu.com/p/3458400116 鉴于本吧多新人,新人又需要多交流才能进步,今天就给新人们讲讲git和maven的必要性,因为,他们的重要性,远远超过很 ...
- Odoo 8 Graph 视图 之 雷达图 (Radar\Spider)
据说7.0是有Radar图的,但是8以后被阉割掉了.自己动手 ,丰衣足食. 经过一天的努力,雷达图现已成功加入群共享套餐.
- javascript 简略
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- callback 回调函数
把函数a当做一个参数传入函数b <script> Array.prototype.mysort = function(callback){ let s = this; //准备向回调函数里 ...
- (原)使用TortoiseGit提交代码push的时候报错:HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large
今天我想rk的sdk包里面的一些东西提交到我的git服务器上,结果,总是报错,折腾了一下午,结果才解决. 首先看看我提交代码的时候,报错的信息: git.exe push --progress &qu ...