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 和官方题 ... 
随机推荐
- Hive 笔试题
			Hive 笔试题 考试时间: 姓名:____________ 考试成绩:____________ 考试时长:180 分钟 注意事项: 1. 自主答题,不能参考任何除本试卷外的其它资料. 2. 总成绩共 ... 
- ubuntu16.04 开启FTP服务
			配置ftp 1.安装 vsftpd服务器 sudo apt install vsftpd 2.创建一个ftp文件夹 (可以跳过) sudo mkdir /home/ftp 3.新建ftp用户,并指向它 ... 
- LeetCode--064--最小路径和
			给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小. 说明:每次只能向下或者向右移动一步. 示例: 输入:[ [1,3,1], [1,5,1], ... 
- Alter改变终结
			#alter#删除date列但若表中只有一个字段无法使用drop删除ALTER TABLE z_staff_info_copy1 DROP `date`;ALTER TABLE z_staff_inf ... 
- HDU 6230 Palindrome ( Manacher && 树状数组)
			题意 : 给定一个字符串S,问你有多少长度为 n 的子串满足 S[i]=S[2n−i]=S[2n+i−2] (1≤i≤n) 参考自 ==> 博客 分析 : 可以看出满足题目要求的特殊回文子串其 ... 
- Packet Transactions: High-level Programming for Line-Rate Switches
			Name of article:Packet Transactions: High-level Programming for Line-Rate Switches Origin of the art ... 
- Twice Equation
			题目链接:https://nanti.jisuanke.com/t/A1541 题意:给你一个L,要你求一个不小于L的最小数字n,对于一个整数m,满足2*(m+1)*m=n*(n+1). 思路:打表找 ... 
- 后端PHP框架laravel学习踩的各种坑
			安装完laravel的ventor目录后出现“Whoops, looks like something went wrong.”这样的错误信息 打开config/app.php,打开debug为tru ... 
- 一台电脑多个git使用 push 时候出现denied
			http://my.oschina.net/silentboy/blog/220158 当一台电脑上多个git account 的时候, 出现如下问题, $ git push origin maste ... 
- WebPack Task Runner
			https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebPackTaskRunner New to WebPack? ... 
