【codeforces 777C】 Alyona and Spreadsheet
【题目链接】:http://codeforces.com/contest/777/problem/C
【题意】
给你n行m列的矩阵;
然后给你k个询问[l,r];
问你在第l到第r行,是否存在一个列,这一列的第l到第r行是升序的;
是输出YES,否则输出NO
【题解】
/*
对于每一列;
从小到大枚举行;
对于第i行;
看看从第i个元素能有序多长,dp[i];
然后对于j (j∈[i..i+dp[i]-1]),dp[j] = dp[i]-(i-j);
然后i = i+dp[i];
记录下第i行,dp[i][1..m]中的最大值;
对于每一个询问;
if (l+dp[l]-1>=r)
则yes,否则no;
*/
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5+100;
vector <int> a[N];
int n, m ,k;
int tdp[N],dp[N];
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(n), rei(m);
rep1(i, 1, n)
{
a[i].pb(-1);
int x;
rep1(j, 1, m)
{
rei(x);
a[i].pb(x);
}
}
rep1(j, 1, m)
{
rep1(i, 1, n)
{
int t = i;
while (t + 1 <= n && a[t][j] <= a[t + 1][j]) t++;
tdp[i] = t - i + 1;
rep1(j, i + 1, t)
tdp[j] = tdp[i] - (j - i);
i = t;
}
rep1(i, 1, n)
dp[i] = max(dp[i], tdp[i]);
}
rei(k);
int l, r;
rep1(i, 1, k)
{
rei(l), rei(r);
if (l + dp[l] - 1 >= r)
puts("Yes");
else
puts("No");
}
return 0;
}
【codeforces 777C】 Alyona and Spreadsheet的更多相关文章
- 【39.66%】【codeforces 740C】Alyona and mex
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【81.82%】【codeforces 740B】Alyona and flowers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【20.23%】【codeforces 740A】Alyona and copybooks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【30.36%】【codeforces 740D】Alyona and a tree
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【31.58%】【codeforces 682D】Alyona and Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces 682C】Alyona and the Tree
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设dis[v]表示v以上的点到达这个点的最大权值(肯定是它的祖先中的某个点到这个点) 类似于最大连续累加和 当往下走(x,y)这条边的时候,设 ...
- Codeforces 777C:Alyona and Spreadsheet(预处理)
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns ho ...
- Codeforces 777C:Alyona and Spreadsheet(思维)
http://codeforces.com/problemset/problem/777/C 题意:给一个矩阵,对于每一列定义一个子序列使得mp[i][j] >= mp[i-1][j],即如果满 ...
- 【CodeForces - 682C】Alyona and the Tree(dfs)
Alyona and the Tree Descriptions 小灵决定节食,于是去森林里摘了些苹果.在那里,她意外地发现了一棵神奇的有根树,它的根在节点 1 上,每个节点和每条边上都有一个数字. ...
随机推荐
- JavaScript 倒计时器,闹钟功能
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- loadrunner监控linux之linux下安装rpc
安装和配置rpc服务 说明:rpc服务需rsh的支持,一般情况下rsh已安装.通过rpm -qa rsh命令查看. 下载rpc.rstatd-4.0.1.tar.gz,可先下载到window下,通过f ...
- Android 文件路径(/mnt/sdcard/...)、Uri(content://media/external/...)
一.URI 通用资源标志符(Universal Resource Identifier, 简称"URI"). Uri代表要操作的数据,Android上可用的每种资源 - 图像.视频 ...
- [Angular] FadeIn and FadeOut animation in Angular
To define an Angular Animation, we using DSL type of language. Means we are going to define few anim ...
- Qt的一些开发技巧
Lambda匿名函数 有时候槽函数代码辑逻辑非常简单,可以直接用下面的Lambda匿名函数处理信号,简捷明了.需c++11支持,不支持自身递归调用. 1 2 3 4 5 6 7 QComboBox * ...
- 【例题 6-7 UVA - 122 】Trees on the level
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二叉树的话,直接用数组存就好了. 写个bfs记录一下答案. [代码] #include <bits/stdc++.h> ...
- zynq mac地址修改
工作中遇到多个zynq板子同时位于一个交换机网络中,由于默认mac地址相同,无法进行通信,因此需要对每个板子修改mac地址. 方案:使用uboot配置文件 步骤: 在uboot配置文件中添加及修改下面 ...
- Understanding Cubert Concepts(一)Partitioned Blocks
Understanding Cubert Concepts(一)Partitioned Blocks Cubert Concepts 对于Cubert,我们要理解其核心的一些概念,比方BLOCK.这些 ...
- UI组件之AdapterView及其子类关系,Adapter接口及事实上现类关系
AdapterView本身是一个抽象基类,它派生的的子类在使用方法上十分类似.AdapterView直接派生的三个子类:AbsListView.AbsSpinner,AdapterViewAnimat ...
- 链表(三)——链表删除冗余结点&插入结点到有序链表
1.一个以递增方式排列的链表,去掉链表中的冗余值. 思路一:设有两个指针p和q.使p不动,q依次往后循环直到p->data不等于q->data,再将中间的冗余数据删除. 思路二:设有两个指 ...