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 和官方题 ...
随机推荐
- git-bash下, 启动sshd
今天发现git-shell下居然有sshd.exe, 尝试了一下,居然起来了.在windiwos下起sshd也是如此简单. #先编辑C:\Program Files (x86)\Git\etc\ssh ...
- clang和llvm的安装
https://blog.csdn.net/qq_31157999/article/details/78906982
- 6411. 【NOIP2019模拟11.06】上网
题目描述 Description Input Output 若无解,则输出"Impossible". 否则第一行输出"Possible",第二行输出 n 个正整 ...
- linux运维、架构之路-cobbler无人值守
一.cobbler介绍 Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装.重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等 1.主要功能:①Cobbl ...
- JavaScript自增和自减
一.自增++ 通过自增运算符可以使变量在自身的基础上加一: 对于一个变量自增以后,原变量的值会立即自增一: 自增符号:++ 自增分为两种:1.后++(a++):2.前++(++a): 共同点:a++ ...
- Quick BI支持哪些数据源(配置操作篇)
Quick BI 潜心打造了核心技术底座(OLAP分析引擎),实现了SQL解析.SQL调度.SQL优化.查询加速等基础能力,支撑Quick BI的数据分析和查询加速.OLAP分析引擎包括数据源连接.数 ...
- document.referer
参考文章: 深入理解document.referrer的用法
- 论文keywords和规则匹配的baseline
详细的思路可以参照小论文树立0317 关键词分为以下几类: t/****一些通用的过滤词,这些通用的过滤词可以使用和节目一起出现的词语,结合tf-idf看出来么?*****/ public st ...
- 有关OI的思维导图
看到这张图 我仿佛掉进了知识的深渊QwQ
- vue +ts 在router的路由中import报错的解决方案
在router.ts中引入.vue文件,会提示打不到module,但是编译可能成功,运行也不报错 找了好久,发现了这个答案 https://segmentfault.com/a/11900000167 ...