【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 上,每个节点和每条边上都有一个数字. ...
随机推荐
- JS搜索菜单实现
1 <!--菜单搜索功能--> 2 <!--先写静态页面--> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 ...
- 关于python的序列和矩阵运算的写法
#其实下面是这样一个函数,传入的是obj_value,传出的是newobj_value.,, #这里的obj_value实际上是一个序列... for z in obj_value: ...
- 【例题 7-1 UVA - 725】Division
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举分母从0到99999. 得到分子,判断合法 [代码] /* 1.Shoud it use long long ? 2.Have ...
- 用多年前据说买买提上理论水平最高的帖子做镇楼贴---NASA有吹牛了
美国国会一直有意把nasa 划入国防部,取消太空探索所关联的部门,因为这些部门都是些烧钱的大包袱,而把具有军事意义的部门留下.国会想把烧钱部卖给google,可能是要价太高,最后没有谈拢,不了了之.但 ...
- 【MemSQL Start[c]UP 3.0 - Round 1 A】 Declined Finalists
[链接]h在这里写链接 [题意] 在这里写题意 [题解] max(最大值-25,0) [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> ...
- Spring Boot 2.x 使用 jpa 连接 mysql
在spring boot网站上生成一个项目,如图: 我使用的是Maven项目,java使用是jdk8(spring boot 2.x必须要jdk8及以上),dependencies分别输入选择 web ...
- UVA 11178 - Morley's Theorem 向量
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 4、runtime电源管理模式(内核文档runtime_pm.txt有详细描述)
系统睡眠模型是让整个系统休眠,而runtime是在系统正常工作的时候单独控制某个设备休眠和唤醒 1. runtime PM流程怎样动态地打开或关闭设备的电源?最简单的方法:在驱动程序里,在open函数 ...
- AE开发技术文档--8种数据访问方法
转自原文 AE开发技术文档--8种数据访问方法 1.shapefile IWorkspaceFactory pWorkspaceFactory; pWorkspaceFactory = new Sha ...
- tensorflow 的 Batch Normalization 实现(tf.nn.moments、tf.nn.batch_normalization)
tensorflow 在实现 Batch Normalization(各个网络层输出的归一化)时,主要用到以下两个 api: tf.nn.moments(x, axes, name=None, kee ...