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

  1. 【39.66%】【codeforces 740C】Alyona and mex

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【30.36%】【codeforces 740D】Alyona and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【31.58%】【codeforces 682D】Alyona and Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【Codeforces 682C】Alyona and the Tree

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 设dis[v]表示v以上的点到达这个点的最大权值(肯定是它的祖先中的某个点到这个点) 类似于最大连续累加和 当往下走(x,y)这条边的时候,设 ...

  7. Codeforces 777C:Alyona and Spreadsheet(预处理)

    During the lesson small girl Alyona works with one famous spreadsheet computer program and learns ho ...

  8. Codeforces 777C:Alyona and Spreadsheet(思维)

    http://codeforces.com/problemset/problem/777/C 题意:给一个矩阵,对于每一列定义一个子序列使得mp[i][j] >= mp[i-1][j],即如果满 ...

  9. 【CodeForces - 682C】Alyona and the Tree(dfs)

    Alyona and the Tree Descriptions 小灵决定节食,于是去森林里摘了些苹果.在那里,她意外地发现了一棵神奇的有根树,它的根在节点 1 上,每个节点和每条边上都有一个数字. ...

随机推荐

  1. v-for实现循环嵌套

    <!DOCTYPE html> <html lang="en"> <head> <title></title> < ...

  2. 使用Invoke解决多线程间的控件访问出错

    // 按钮点击事件处理程序private void button1_Click(object sender, EventArgs e){    //创建新线程    Thread processorT ...

  3. js进阶 14-2 如何用ajax验证登陆状态(这里用load方法)

    js进阶 14-2 如何用ajax验证登陆状态(这里用load方法) 一.总结 一句话总结:$('#test').load('test.php?password=1234560'),这样就get方式提 ...

  4. 百度2019校招Web前端工程师笔试卷(9月14日)

    8月27日晚,在实习公司加班.当时正在调试页面,偶然打开百度首页console,发现彩蛋,于是投了简历. 9月14日晚,七点-九点,在公司笔试. 笔试题型(有出入): 一.单选20道 1.难度不难,考 ...

  5. Hadoop3.0配置

    1.core-site.xml <configuration> <property> <name>fs.default.namenode</name> ...

  6. [Nuxt] Add CSS Libraries to Nuxt

    You can easily add CSS libraries to Nuxt using yarn or npm to install them, then simply adding them ...

  7. FragmentPagerAdapter和FragmentStatePagerAdapter的差别

    ViewPager同意用户通过左右滑动显示不同页面的数据.而这些页面须要PagerAdapter管理. 经常使用的有FragmentPagerAdapter和FragmentStatePagerAda ...

  8. NoSql中的B-tree、B+tree和LSM-tree 分类: B7_HBASE 2015-03-15 18:27 85人阅读 评论(0) 收藏

    总结: 1.B+树将数据完全排序,读数据时很快,但当要修改数据时,就需要将新入数据下面的数据重新排位,特别是当写入的数据排在较高的位置时,需要大量的移位操作才能完成写入. 2.SLM牺牲部分的读性能, ...

  9. URL validation failed. The error could have been caused through the use of the browser&#39;s navigation

    URL validation failed. The error could have been caused through the use of the browser's navigation ...

  10. 改变HTML中超链接的显示样式 分类: C1_HTML/JS/JQUERY 2014-08-27 10:11 595人阅读 评论(0) 收藏

    更详细的内容请参考:http://www.w3school.com.cn/tags/tag_a.asp HTML中的代码如下: <a class="news_title" t ...