Codeforces - 6E - Exposition - 尺取
https://codeforc.es/problemset/problem/6/E
既然可以多个log,那就直接map伺候。尺取之后要查询区间里面的最大值和最小值的差。众所周知尺取的时候要是不是有序序列,不可能方便地维护极值。(或者不用map以及平衡树的话,那就用线段树,每次update一个数量,然后RMQ最值,线段树(假如不是这个范围)还得先离散化,非常傻逼)。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
int h[100005];
map<int, int> m;
vector<int> b;
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i)
scanf("%d", &h[i]);
int maxlen = 0;
b.resize(n);
for(int l = 1, r = 1; r <= n; ++r) {
++m[h[r]];
while(m.rbegin()->first - m.begin()->first > k) {
if(m[h[l]] == 1)
m.erase(h[l]);
else
--m[h[l]];
++l;
}
if(maxlen < r - l + 1) {
maxlen = r - l + 1;
b.clear();
b.push_back(l);
} else if(maxlen == r - l + 1)
b.push_back(l);
}
printf("%d %d\n", maxlen, b.size());
for(auto i : b)
printf("%d %d\n", i, i + maxlen - 1);
}
Codeforces - 6E - Exposition - 尺取的更多相关文章
- Codeforces - 1199C - MP3 - 尺取
https://codeforc.es/contest/1199/problem/C 擦,最后移位运算符溢出了,真的蠢. 肯定是选中间的连续的某段是最优的,维护这个段的长度和其中的元素种类就可以了.小 ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】
任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...
- 【尺取或dp】codeforces C. An impassioned circulation of affection
http://codeforces.com/contest/814/problem/C [题意] 给定一个长度为n的字符串s,一共有q个查询,每个查询给出一个数字m和一个字符ch,你的操作是可以改变字 ...
- Codeforces 939E Maximize! (三分 || 尺取)
<题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...
- B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot(二分或者尺取)
题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1; 这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x, ...
- Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)
排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...
- Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取
https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...
随机推荐
- Docker(三):Docker入门教程-CentOS Docker 安装
CentOS Docker 安装 Docker支持以下的CentOS版本: CentOS 7 (64-bit) CentOS 6.5 (64-bit) 或更高的版本 前提条件 目前,CentOS 仅发 ...
- Navicat 出现的[Err] 1146 - Table 'performance_schema.session_status' doesn't exist已解决
[Err] 1146 - Table 'performance_schema.session_status' doesn't exist已解决 刚刚接触MySQL,就往数据库添加数据,就遇到这个问 ...
- 20180829-Java多线程编程
Java 多线程编程 Java给多线程编程提供了内置的支持.一个多线程程序包含两个或多个能并发运行的部分. 程序的每一部分都称作一个线程,并且每个线程定义了一个独立的执行路径. 多线程是多任务的一种特 ...
- Socket网络通信编程(一)
1.学习基本概念.传统的同步阻塞式I/O编程.伪异步IO实现 2.学习基于NIO的同步非阻塞式编程 3.了解基于NIO2.0的异步非阻塞(AIO)编程 1.1 基本概念 Socket又称“套接字”,应 ...
- Oracle And子句
Oracle And子句 作者:初生不惑 Oracle基础 评论:0 条 Oracle技术QQ群:175248146 在本教程中,将学习如何使用Oracle AND运算符来组合两个或更多的布尔表达式. ...
- [spring cloud feign] [bug] 使用对象传输get请求参数
前言 最近在研究 srping cloud feign ,遇到了一个问题,就是当 get 请求 的参数使用对象接收时,就会进入熔断返回.经过百度,发现网上大部分的解决方案都是将请求参数封装到Reque ...
- 插头DP讲解+[BZOJ1814]:Ural 1519 Formula 1(插头DP)
1.什么是插头$DP$? 插头$DP$是$CDQ$大佬在$2008$年的论文中提出的,是基于状压$D$P的一种更高级的$DP$多用于处理联通问题(路径问题,简单回路问题,多回路问题,广义回路问题,生成 ...
- VS2015中添加QT5.9.0插件
https://blog.csdn.net/hhhuang1991/article/details/79768595 VS2015里使用QTDIR路径查找QT开发包目录 路径配置操作系统环境变量里添加 ...
- db2数据库表操作错误SQL0668N Operation not allowed for reason code "1" on table "表". SQLSTATE=57016的解决方法
错误sql Operation not allowed for reason code "1" on table "MARKET.PURE_USER".. SQ ...
- 高通Android camera运行流程【转】
本文转载自:http://blog.csdn.net/unicornkylin/article/details/13293295 1.总体架构 Android Camera 框架从整体上看是一个 cl ...