题意:给你一个数组a,定义:若a[i]>a[i]&&a[i]>a[i-1],则a[i]为峰值,求长度为k的区间内峰值最多能为多少,并输出这个区间的左端点(区间需要将峰的左边和右边都包括)

题解:记录每个峰值,然后搞一个后缀和,从前往后枚举长度为k的区间,每次维护一下最多的峰值和区间位置即可.

tips:注意边界,区间左端点l要初始化成1(我初始化的是0,wa了一整场~(>_<)~)

代码:

 1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <stack>
7 #include <queue>
8 #include <vector>
9 #include <map>
10 #include <set>
11 #include <unordered_set>
12 #include <unordered_map>
13 #define ll long long
14 #define fi first
15 #define se second
16 #define pb push_back
17 #define me memset
18 const int N = 1e6 + 10;
19 const int mod = 1e9 + 7;
20 using namespace std;
21 typedef pair<int,int> PII;
22 typedef pair<long,long> PLL;
23
24 int t;
25 int n,k,a[N];
26 map<int,int> top,pre;
27 int main() {
28 ios::sync_with_stdio(false);
29 cin>>t;
30 while(t--){
31 cin>>n>>k;
32 top.clear();
33 pre.clear();
34 for(int i=1;i<=n;++i) cin>>a[i];
35 for(int i=2;i<n;++i){
36 if(a[i]>a[i-1] && a[i]>a[i+1]){
37 top[i]=1;
38 pre[i]=1;
39 }
40 }
41 for(int i=n+k;i>=1;--i) pre[i]=pre[i+1]+pre[i];
42 int res=0,pos=1;
43 for(int i=1;i<=n;++i){
44 int tmp=pre[i]-pre[i-1+k]-top[i];
45 if(tmp>res){
46 res=tmp;
47 pos=i;
48 }
49 }
50 printf("%d %d\n",res+1,pos);
51 }
52 return 0;
53 }

Codeforces #637 div2 B. Nastya and Door的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  8. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  9. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. mysql .sock丢时候如何链接数据库

    在mysql服务器本机上链接mysql数据库时,经常会噢出现mysql.sock不存在,导致无法链接的问题,这是因为如果指定localhost作为一个主机名,则mysqladmin默认使用unix套接 ...

  2. 【Linux】nginx详细说明

    Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目 ...

  3. oracle关闭监听log.xml文件生成步骤

    1.查看sqlnet.ora文件是否存在 cd $ORACLE_HOME/network/admin ls 如果不存在,copy一个过来 cp samples/sqlnet.ora . 2.修改sql ...

  4. SAPCAR使用说明

    1.首先看一下SAPCAR的功能usage:create a new archive:SAPCAR -c[vir][f archive] [-P] [-C directory]   [-A filen ...

  5. 24V转3.3V稳压芯片,高效率同步降压DC-DC变换器3A输出电流

    PW2312是一个高频,同步,整流,降压,开关模式转换器与内部功率MOSFET.它提供了一个非常紧凑的解决方案,以实现1.5A的峰值输出电流在广泛的输入电源范围内,具有良好的负载和线路调节. PW23 ...

  6. 在.NET Core 中实现健康检查

    .NET Core中提供了开箱即用的运行状况检查,首先,我将在.NET Core API应用程序中执行运行状况检查,接下来,我们将使用DbContext集成SQL Server或数据库的运行状况检查, ...

  7. 六个你不知道的PR快捷键,拯救你的剪辑效率

    5G时代到来,会剪辑视频的人,无论在校园还是未来步入职场都很吃香.对于普通人来说,视频处理也成为了一个通用技能.PR是我们大多数人剪辑中,经常会用到的剪辑工具,之前的文章中已经给大家总结了pr的一些提 ...

  8. windows和linux修改ipv6和ipv4的优先级

    如果一台机器系统配置ipv6地址和ipv4地址共存,访问两种网站都可以 但有个很尴尬的问题,因为操作系统默认是V6优先于V4,所以比如一个地址同时有A和AAAA记录的话,那么系统会自动选择V6协议通信 ...

  9. 【Soul源码探秘】插件链实现

    引言 插件是 Soul 的灵魂. Soul 使用了插件化设计思想,实现了插件的热插拔,且极易扩展.内置丰富的插件支持,鉴权,限流,熔断,防火墙等等. Soul 是如何实现插件化设计的呢? 一切还得从插 ...

  10. Java层面上下文切换

    前言 在过去单CPU时代,单任务在一个时间点只能执行单一程序.之后发展到多任务阶段,计算机能在同一时间点并行执行多任务或多进程.虽然并不是真正意义上的"同一时间点",而是 多个任务 ...