Alyona and Spreadsheet

这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢?

【题目链接】Alyona and Spreadsheet

&题意:

给一n*m的表,之后给T个询问,每个询问是r1和r2,问从r1行到r2行(包括这2行)是否至少有一列是非递减的?

&题解:

可以把给的n*m表处理一下,处理成b[i][j]数组,存的是第j列递增开始的位置是第几行.

这样,只有b中第r2行最小的小于r1就行了,否则就是No

【时间复杂度】\(O(max(q,n*m))\)q是询问次数

&代码:

#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn= 1e3 +9,INF=0x3f3f3f3f;
int n,m;
vector<vector<int> > a,b;
vector<int> c;
int main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// freopen("C:\\Users\\Zmy\\Desktop\\in.txt", "r", stdin);
cin>>n>>m;
a.resize(n);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
int t;
cin>>t;
a[i].push_back(t);
}
b=a;
for(int i=0;i<m;i++) b[0][i]=0;
for(int i=0;i<m;i++)
for(int j=1;j<n;j++){
if(a[j][i]>=a[j-1][i]){
b[j][i]=b[j-1][i];
}
else{
b[j][i]=j;
}
}
c.resize(n);
for(int i=0;i<n;i++){
c[i]=INF;
for(int j=0;j<m;j++){
c[i]=min(c[i],b[i][j]);
}
}
int T;
cin>>T;
for(int i=0;i<T;i++){
int r1,r2;
cin>>r1>>r2;
if(c[r2-1]<=r1-1)
puts("Yes");
else
puts("No");
}
return 0;
}

C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)的更多相关文章

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

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

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

  3. Codeforces Round #401 (Div. 2)

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

  4. Codeforces Round #401 (Div. 2) A,B,C,D,E

    A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...

  5. Codeforces Round #401 (Div. 2) A B C 水 贪心 dp

    A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...

  6. 【离线】【递推】【multiset】 Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet

    对询问按右端点排序,对每一列递推出包含当前行的单调不下降串最多向前延伸多少. 用multiset维护,取个最小值,看是否小于等于该询问的左端点. #include<cstdio> #inc ...

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

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

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

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

  9. Codeforces Round #401 (Div. 1) C(set+树状数组)

    题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...

随机推荐

  1. Hot Plug Detection, DDC, and EDID

    Hot Plug Detection, DDC, and EDID DataPro Tech Info > Hot Plug Detection, DDC, and EDID Hot Plugg ...

  2. 编译openssl和Apache报错checking for SSL_CTX_new... no

    执行export LDFLAGS=-ldl命令后重新编译

  3. [development][dpdk][pktgen] 网卡收发包性能测试

    一: 多队列及中断信息收集 [root@T185 ~]# ethtool -g eth0 Ring parameters for eth0: Pre-set maximums: RX: RX Mini ...

  4. 转:EL表达式的11个内置对象

    原文地址:https://blog.csdn.net/qq_17045385/article/details/54799998 EL是JSP内置的表达式语言 JSP2.0开始,不让再使用Java脚本, ...

  5. kafka相关命令

    查看kafka消费组对应的信息:./kafka-consumer-groups.sh --bootstrap-server 172.17.6.10:9092 --describe --group fr ...

  6. 离线应用与客户端存储(cookie storage indexedDB)

    离线检测 HTML5定义一个属性:navigator.onLine的属性.这个属性值为true,表示设备在线,值为false,表示设备离线.为了更好的确定网络是否可用,HTML5还定义了两个事件.这两 ...

  7. 关于 Data URI Scheme -- data:image/jpg;base64

    转载一篇大神的文章 大家可能注意到了,网页上有些图片的src或css背景图片的url后面跟了一大串字符,比如: data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqA ...

  8. 并查集——易爆物D305

    部分内容摘自博客http://blog.csdn.net/u012881011/article/details/46883863,感谢 易爆物D305             运行时间限制:1000m ...

  9. linux中按照指定内容查找文件

    grep -rnRi 指定的内容 * | awk -F":" '{print $1}' 解释: grep 查找文件内容 -r 表示递归查找 -n 表示显示行号 -R 表示查找所有文 ...

  10. oracle闪回的使用

    1.闪回查询(原理:依赖于UNDO表空间)查询当前SCN号select current_scn from v$database;误删数据以后select * from table_name as of ...