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 - 尺取的更多相关文章

  1. Codeforces - 1199C - MP3 - 尺取

    https://codeforc.es/contest/1199/problem/C 擦,最后移位运算符溢出了,真的蠢. 肯定是选中间的连续的某段是最优的,维护这个段的长度和其中的元素种类就可以了.小 ...

  2. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

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

  4. 【尺取或dp】codeforces C. An impassioned circulation of affection

    http://codeforces.com/contest/814/problem/C [题意] 给定一个长度为n的字符串s,一共有q个查询,每个查询给出一个数字m和一个字符ch,你的操作是可以改变字 ...

  5. Codeforces 939E Maximize! (三分 || 尺取)

    <题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...

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

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

  8. Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)

    排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...

  9. Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取

    https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...

随机推荐

  1. [原创]Laravel 基于redis队列的解析

    目录 参考链接 本文环境 为什么使用队列 Laravel 中的队列 分发任务 任务队列 Worker Last-Modified: 2019年5月10日11:44:18 参考链接 使用 Laravel ...

  2. CSS3实现三角形和对话框

    这是最终实现的效果,类似于微信对话框的样式. 分析一下这个对话框的结构,由一个小三角形和一个长方形构成.长方形很容易就可以实现,重点是如何用CSS3做出一个小三角形. 一.如何生成一个三角形  总结: ...

  3. [USACO08FEB]连线游戏Game of Lines

    题目背景 Farmer John最近发明了一个游戏,来考验自命不凡的贝茜. 题目描述 Farmer John has challenged Bessie to the following game: ...

  4. 关联规则挖掘--Apriori算法

  5. CF1019E Raining season

    https://www.luogu.org/problemnew/show/CF1019E 题解 \[ dis=day*a+b \] \[ b=-day*a+dis \] 然后就变成了斜率优化. 考虑 ...

  6. IDEA集成java编程规范插件

    第一种:如图所示搜索 Alibaba Java Coding Guidelines(阿里巴巴) 安装完成后,重启idea,点击tools>阿里巴巴编程>编程规约扫描 即可

  7. SQL ORDER BY 两个列

    ORDER BY  后可加2个字段,用英文逗号隔开. f1用升序, f2降序,sql该这样写 ORDER BY  f1, f2  DESC 也可以这样写,更清楚: ORDER BY  f1 ASC, ...

  8. ionic使用自定义icon

    参考文档:https://www.jianshu.com/p/5346fee9fd80  angular+ionic 自定义图标 注意: 这里不用name 用class类名显示出来 最后出来图标是个小 ...

  9. 协议-TCP:TCP

    ylbtech-协议-TCP:TCP 传输控制协议(TCP,Transmission Control Protocol)是一种面向连接的.可靠的.基于字节流的传输层通信协议,由IETF的RFC 793 ...

  10. FOUC(Flash Of Unstyled Content)文档样式闪烁

    今天看面试题看到了这个新名词..我以前是没有发现过这种状况,应该是我一直都是将加载 CSS 的 link 标签写到 head 里的缘故吧. 什么是文档样式闪烁(Flash Of Unstyled Co ...