题意:给你一个数组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. 怎么启用apache的mod_log_sql模块将所有的访问信息直接记录在mysql中

    怎么启用apache的mod_log_sql模块将所有的访问信息直接记录在mysql中

  2. ctfhub技能树—sql注入—Refer注入

    手注 查询数据库名 查询数据表名 查询字段名 查询字段信息 脚本(from 阿狸) #! /usr/bin/env python # _*_ coding:utf-8 _*_ url = " ...

  3. SAP中的F4帮助

    今天在调试标准程序的时候,意外的发现了一个F4帮助的函数,感觉还是挺好用的. F4IF_FIELD_VALUE_REQUEST从函数名就可以看出是给字段添加F4帮助的. F4 help for fie ...

  4. ABAP 多表联合查询

    inner join(等值连接) 只返回两个表中联结字段相等的行left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录right join(右联接) 返回包括右表中的所有记录 ...

  5. 15V转5V转3.3V转3V芯片,DC-DC和LDO

    15V电压是属于一般电压,降压转成5V电压,3.3V电压和3V电压,适用于这个电压的DC-DC很多,LDO也是有可以选择的.LDO芯片如PW6206,PW8600等.DC-DC芯片如:PW2162,P ...

  6. 前端知识(二)03-Webpack-谷粒学院

    目录 一.什么是Webpack 二.Webpack安装 1.全局安装 2.安装后查看版本号 三.创建项目 1.初始化项目 2.创建src文件夹 3.src下创建common.js 4.src下创建ut ...

  7. Mybatis【15】-- Mybatis一对一多表关联查询

    注:代码已托管在GitHub上,地址是:https://github.com/Damaer/Mybatis-Learning ,项目是mybatis-11-one2one,需要自取,需要配置maven ...

  8. C++ 中assert断言函数的基本用法

    在我们的实际开发过程之中,常常会出现一些隐藏得很深的BUG,或者是一些概率性发生的BUG,通常这些BUG在我们调试的过程中不会出现很明显的问题,但是如果我们将其发布,在用户的各种运行环境下,这些程序可 ...

  9. [从源码学设计] Flume 之 memory channel

    [从源码学设计] Flume 之 memory channel 目录 [从源码学设计] Flume 之 memory channel 0x00 摘要 0x01 业务范畴 1.1 用途和特点 1.2 C ...

  10. Python_ 1生成器(上)初识生成器

    引言:列表生成式 现在有个需求,给定列表[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],现在要求你把列表里的每个值加1,你怎么实现?你可能会想到2种方式 1 >>> a ...