Codeforces 777C Alyona and Spreadsheet(思维)
记a[i][j]为读入的矩阵,c[i][j]为满足a[i][j],a[i - 1][j], a[i - 2][j],......,a[k][j]不上升的k的最小值。
d[i]为max(c[i][j]) (1 <= j <= m)
那么对于每次询问l,r,若d[r] <= l,那么就符合,反之不符。
因为这里只说名了1 <= nm <= 100000,所以二维数组两个维的大小不确定。
数据可能有n=1, m=100000,也可能有n = 100000, m = 1。
所以我把二维数组开成了一维的。
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i(a); i <= (b); ++i)
#define INF 1 << 30 const int N = + ; int a[N], c[N], d[N];
int n, m, q, x, y; int calc(int i, int j){
return (i - ) * m + j;
} int main(){ scanf("%d%d", &n, &m);
rep(i, , m) scanf("%d", a + i);
rep(i, , m) c[calc(, i)] = ;
rep(i, , n){
rep(j, , m){
scanf("%d", &x);
if (a[j] <= x){
c[calc(i, j)] = c[calc(i - , j)];
a[j] = x;
} else{
c[calc(i, j)] = i;
a[j] = x;
}
}
} rep(i, , n) d[i] = INF;
rep(i, , n){
rep(j, , m) d[i] = min(d[i], c[calc(i, j)]);
} scanf("%d", &q);
while (q--){
scanf("%d%d", &x, &y);
puts(d[y] <= x ? "Yes" : "No");
} return ; }
Codeforces 777C Alyona and Spreadsheet(思维)的更多相关文章
- Codeforces 777C Alyona and Spreadsheet
C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...
- Codeforces 777C - Alyona and Spreadsheet - [DP]
题目链接:http://codeforces.com/problemset/problem/777/C 题意: 给定 $n \times m$ 的一个数字表格,给定 $k$ 次查询,要你回答是否存在某 ...
- codeforces 777C.Alyona and Spreadsheet 解题报告
题目链接:http://codeforces.com/problemset/problem/777/C 题目意思:给出一个 n * m 的矩阵,然后问 [l, r] 行之间是否存在至少一列是非递减序列 ...
- C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)
Alyona and Spreadsheet 这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢? [题目链接]Alyona and Spre ...
- 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 ...
- codeforces 777C
C.Alyona and Spreadsheet During the lesson small girl Alyona works with one famous spreadsheet compu ...
- Codeforces777C Alyona and Spreadsheet 2017-05-04 17:46 103人阅读 评论(0) 收藏
C. Alyona and Spreadsheet time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces E. Alyona and a tree(二分树上差分)
题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 777C:Alyona and Spreadsheet(思维)
http://codeforces.com/problemset/problem/777/C 题意:给一个矩阵,对于每一列定义一个子序列使得mp[i][j] >= mp[i-1][j],即如果满 ...
随机推荐
- POJ 3370 Halloween treats(抽屉原理)
Halloween treats Every year there is the same problem at Halloween: Each neighbour is only willing t ...
- Eclipse安装MAT插件
MAT(Memory Analyzer Tool) 是基于heap dumps来进行分析的,它的分析速度比jhat快,分析结果是图形界面显示,比java内置jhat的可读性更高 通过Eclipse市场 ...
- Lucene.Net 精品教程
http://www.cnblogs.com/piziyimao/archive/2013/01/31/2887072.html
- 【Scramble String】cpp
题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty subs ...
- Python-S9-Day89_stark总结
01 Stark总结 02 ORM总结 03 上节作业 04 Stark组件之查看页面表头 05 list_display_links 06 stark组件之添加页面 07 编辑删除页面 01 Sta ...
- [oldboy-django][2深入django]学生管理(Form)-- 编辑(设置input标签属性,设置input标签默认显示值,设置input的类型)
1 django 后台实现设置input标签属性,设置input标签默认显示值,设置input输入框类型 # Form生成html标签 a. 通过Form生成Input输入框,Form标签,以及sub ...
- 如何利用c++编写不能被继承、但可以在类外定义对象的类
#include <iostream> #include<string> #include<map> #include<vector> #include ...
- poj3748 位运算 bitset
位操作 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9064 Accepted: 3626 Description 假 ...
- linux系统——日志文件系统及性能分析
Linux日志文件系统及性能分析 日志文件系统可以在系统发生断电或者其它系统故障时保证整体数据的完整性,Linux是目前支持日志文件系统最多的操作系统之一,本文重点研究了Linux常用的日志文件系统: ...
- shell总结
1. shell脚本的变量赋值 变量赋值语句中的等号左右不能有空格 即 a = 4 //错误 a=4 //正确 2. shell脚步的执行需要权限 chmod +x shell.sh ./shel ...