Codeforces 777C:Alyona and Spreadsheet(思维)
http://codeforces.com/problemset/problem/777/C
题意:给一个矩阵,对于每一列定义一个子序列使得mp[i][j] >= mp[i-1][j],即如果满足这样的情况,那么序列长度+1。给出q个询问,问[l,r]的行区间内是否有一个这样的子序列。
思路:用两个数组,第一个数组row记录每一列到第i行的序列长度,第二个数组ans记录每一行到第j列最长的序列长度。然后询问的时候判断ans[r]是否有区间长度大就可以了。
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4 1 : row[0] = 1, row[1] = 1, row[2] = 1, row[3] = 1. ans[1] = 1.
2 : row[0] = 2, row[1] = 1, row[2] = 2, row[3] = 1. ans[2] = 2.
3 : row[0] = 3, row[1] = 2, row[2] = 1, row[3] = 2. ans[3] = 3.
以此类推
#include <bits/stdc++.h>
using namespace std;
#define N 100100
typedef long long LL;
const int INF = 0x3f3f3f3f;
vector<int> mp[N];
int ans[N], row[N];
// row维护的是每一列向上延伸能达到的长度
// ans维护的是当前这一行向上延伸能够达到的最大序列长度,由row取最优得到
// 如果ans[r] >= r - l + 1,说明这个区间长度是大于等于[l,r]的 int main() {
int n, m;
scanf("%d%d", &n, &m);
for(int i = ; i < n; i++) {
for(int j = ; j < m; j++) {
row[j] = ;
int a; scanf("%d", &a);
mp[i].push_back(a);
}
}
ans[] = ;
for(int i = ; i < n; i++) {
int ma = ;
for(int j = ; j < m; j++) {
if(mp[i][j] >= mp[i-][j]) row[j]++;
else row[j] = ;
if(ma < row[j]) ma = row[j];
}
ans[i+] = ma;
}
int q;
scanf("%d", &q);
while(q--) {
int l, r;
scanf("%d%d", &l, &r);
if(ans[r] >= r - l + ) puts("Yes");
else puts("No");
}
return ;
}
Codeforces 777C:Alyona and Spreadsheet(思维)的更多相关文章
- 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
C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...
- Codeforces 777C - Alyona and Spreadsheet - [DP]
题目链接:http://codeforces.com/problemset/problem/777/C 题意: 给定 $n \times m$ 的一个数字表格,给定 $k$ 次查询,要你回答是否存在某 ...
- codeforces 777C.Alyona and Spreadsheet 解题报告
题目链接:http://codeforces.com/problemset/problem/777/C 题目意思:给出一个 n * m 的矩阵,然后问 [l, r] 行之间是否存在至少一列是非递减序列 ...
- C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)
Alyona and Spreadsheet 这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢? [题目链接]Alyona and Spre ...
- 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 ...
- codeforces 777C
C.Alyona and Spreadsheet During the lesson small girl Alyona works with one famous spreadsheet compu ...
- 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 E. Alyona and a tree(二分树上差分)
题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- WPF 窗体显示最前端
原文:WPF 窗体显示最前端 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/jjx0224/article/details/8782845 如何做一 ...
- cocos2D-X从的源代码的分析cocos2D-X学习OpenGL(1)----cocos2D-X渲染架构
个人原创.欢迎转载,转载请注明原文地址http://blog.csdn.net/bill_man 从本篇文章開始,将分析cocos2D-X 3.0源码,第一部分是从cocos2D-X学习OpenGL ...
- Angular语法(三)——数据绑定
绑定类型 绑定类型可以按照数据流的方向分为三类:从源到视图,从视图到源,以及双向序列 示例 <!-- Bind button disabled state to `isUnchanged` pr ...
- jquery 标签页
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- MVC 调试路由
1.添加引用RouteDebug.dll 2 修改Global.asax,切记调试过后要删掉 using System;using System.Collections.Generic;using S ...
- WPF Calendar 日历控件 样式自定义
原文:WPF Calendar 日历控件 样式自定义 粗略的在代码上做了些注释 blend 生成出来的模版 有的时候 会生成 跟 vs ui界面不兼容的代码 会导致可视化设计界面 报错崩溃掉 但是确不 ...
- jquery实现div拖拽
1.引入jquery1.8.3 ,模块拖拽js代码: //模块拖拽 $(function(){ var _move=false;//移动标记 var _x,_y;//鼠标离控件左上角的相对位置 $(& ...
- erp的核心代码,替代orm
public static SqlParameter[] get_array_list<T>(ArrayList rows) where T : class { Hashtable sql ...
- 零元学Expression Blend 4 - Chapter 23 Deep Zoom Composer与Deep Zoom功能
原文:零元学Expression Blend 4 - Chapter 23 Deep Zoom Composer与Deep Zoom功能 最近有机会在工作上用到Deep Zoom这个功能,我就顺便介绍 ...
- 变量的选择——Lasso&Ridge&ElasticNet
对模型参数进行限制或者规范化能将一些参数朝着0收缩(shrink).使用收缩的方法的效果提升是相当好的,岭回归(ridge regression,后续以ridge代称),lasso和弹性网络(elas ...