对询问按右端点排序,对每一列递推出包含当前行的单调不下降串最多向前延伸多少。

用multiset维护,取个最小值,看是否小于等于该询问的左端点。

#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
multiset<int>S;
#define INF 2147483647
struct Data
{
int l,r,p;
}b[100010];
bool cmp(const Data &a,const Data &b)
{
return a.r<b.r;
}
int n,m,q,ls[100010];
bool anss[100010];
vector<int>a[100010];
int main()
{
// freopen("c.in","r",stdin);
int x;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
a[i].push_back(0);
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
scanf("%d",&x);
a[i].push_back(x);
}
scanf("%d",&q);
for(int i=1;i<=m+1;++i)
a[0].push_back(INF);
for(int i=1;i<=q;++i)
{
scanf("%d%d",&b[i].l,&b[i].r);
b[i].p=i;
}
sort(b+1,b+1+q,cmp);
for(int i=1;i<=q;++i)
{
for(int j=b[i-1].r+1;j<=b[i].r;++j)
for(int k=1;k<=m;++k)
if(a[j][k]<a[j-1][k])
{
multiset<int>::iterator it=S.find(ls[k]);
if(it!=S.end())
S.erase(it);
ls[k]=j;
S.insert(j);
}
if((*S.begin())<=b[i].l)
anss[b[i].p]=1;
}
for(int i=1;i<=q;++i)
puts(anss[i] ? "Yes" : "No");
return 0;
}

【离线】【递推】【multiset】 Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet的更多相关文章

  1. 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 ...

  2. 递推DP Codeforces Round #260 (Div. 1) A. Boredom

    题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...

  3. 【递推】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] D. XOR-pyramid

    题意:定义,对于a数组的一个子区间[l,r],f[l,r]定义为对该子区间执行f操作的值.显然,有f[l,r]=f[l,r-1] xor f[l+1,r].又定义ans[l,r]为满足l<=i& ...

  4. Codeforces Round #401 (Div. 2) 离翻身就差2分钟

    Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35 ...

  5. 【贪心】【multiset】 Codeforces Round #401 (Div. 2) B. Game of Credit Cards

    对第一个人的排序,然后从小到大处理,对第一个人的每枚卡片,从第二个人的卡片中选择一个大于等于它的最小的,否则选择一个当前剩下的最小的,这样可以保证负场最少. 如果选择的改成大于它的最小的,就可以保证胜 ...

  6. 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table

    题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...

  7. Codeforces Round #401 (Div. 2) D Cloud of Hashtags —— 字符串

    题目链接:http://codeforces.com/contest/777/problem/D 题解: 题意:给出n行字符串,对其进行字典序剪辑.我自己的想法是正向剪辑的,即先对第一第二个字符串进行 ...

  8. Codeforces Round #401 (Div. 2)

    和FallDream dalao一起从学长那借了个小号打Div2,他切ABE我做CD,我这里就写下CD题解,剩下的戳这里 AC:All Rank:33 小号Rating:1539+217->17 ...

  9. D Cloud of Hashtags Codeforces Round #401 (Div. 2)

    Cloud of Hashtags [题目链接]Cloud of Hashtags &题意: 给你一个n,之后给出n个串,这些串的总长度不超过5e5,你要删除最少的单词(并且只能是后缀),使得 ...

随机推荐

  1. 如何用Ajax传一个数组数据

    PHP接收多个同名复选框信息不像ASP那样自动转换成为数组,这给使用带来了一定不便.但是还是有解决办法的,就是利用javascript做一下预处 理.多个同名复选框在javascript中还是以数组的 ...

  2. Linux下只允许用户远程scp

    本文将介绍在Linux环境下,让用户不能远程登录 只能使用scp命令 使用到的软件:rssh(http://pizzashack.org/rssh/index.shtml ) 环境:centos6.x ...

  3. iOS 后台运行执行代码(例如定位)

  4. POJ1182 食物链---(经典种类并查集)

    题目链接:http://poj.org/problem?id=1182   食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  5. HDU1016 素数环---(dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1016 Sample Input 6 8   Sample Output Case 1: 1 4 3 2 5 6 ...

  6. 【Foreign】最大割 [线性基]

    最大割 Time Limit: 15 Sec  Memory Limit: 256 MB Description Input Output Sample Input 3 6 1 2 1 1 2 1 3 ...

  7. bzoj4759 [Usaco2017 Jan]Balanced Photo

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4759 [题解] 排序,从大到小插入,树状数组统计. # include <vector ...

  8. [vue-router] Failed to resolve async component default: Error: Loading chunk 0 failed.

    在整合laravel5.4 和vue2.1的时候遇到一个奇怪的问题 Uncaught SyntaxError: Unexpected token < Error: Loading chunk 0 ...

  9. Codeforces Round #391 A B C D E

    A. Gotta Catch Em' All! 题意 从给定的字符串中选取字符,问可构成多少个\(Bulbasaur\) // 想到柯南里一些从报纸上剪汉字拼成的恐吓信_(:з」∠)_ Code #i ...

  10. Linux+Python高端运维班第六周作业

    1.复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#:         [root@localhost tm ...