Codeforces #637 div2 B. Nastya and Door

题意:给你一个数组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的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
随机推荐
- 安装蓝鲸paas社区版
安装蓝鲸paas社区版http://docs.bk.tencent.com/bkce_install_guide/setup/get_ready.html#hostssystemctl stop fi ...
- C++中的extern“C”
首先引入extern"C"的官方解释 extern "C" is meant to be recognized by a C++ compiler and to ...
- 【Linux】Linux基础命令 - 目录相关的命令 ls 、cd、du
文章目录 目录相关的命令 ls 命令:列出文件和目录 cd 命令:切换目录 du 命令:显示目录包含的文件大小 总结 参考资料 巩固和复习Linux系统基础命令知识 目录相关的命令 ls 命令:列出文 ...
- 【Zabbix】配置zabbix agent向多个server发送数据
1.背景: server端: 172.16.59.197 ,172.16.59.98 agent 端: hostname:dba-test-hzj02 IP:172.16.59.98 2.方式: 配 ...
- 攻防世界 - Crypto(一)
base64: 根据题目base64可知编码方式,下载附件发现是一个txt文件,把内容用工具解码就彳亍了,即可得到flag, flag: cyberpeace{Welcome_to_new_World ...
- Sentry(v20.12.1) K8S 云原生架构探索,1分钟上手 JavaScript 性能监控
系列 Sentry-Go SDK 中文实践指南 一起来刷 Sentry For Go 官方文档之 Enriching Events Snuba:Sentry 新的搜索基础设施(基于 ClickHous ...
- openshift 3.11安装部署
openshift 3.11 安装部署 openshift安装部署 1 环境准备(所有节点) openshift 版本 v3.11 1.1 机器环境 ip cpu mem hostname OSsys ...
- 浅谈JavaScript代码性能优化2
一.减少判断层级 从下图代码中可以明显看出,同样的效果判断层级的减少可以优化性能 二.减少作用域链查找层级 简单解释下,下图中第一个运行foo函数,bar函数内打印name,bar作用域内没有name ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(89)-国际化,本地化,多语言应用
开篇 早年写过一篇多语言的应用 : 本地化(多语言) 讲述了如何创建多语言的资源文件,并利用资源文件来获得页面和请求的语言属性 本次补充这篇文章,的原因是在实际项目中,有多种需要多语言的情况 ...
- uni-app开发经验分享十七: 开发微信公众号(H5)JSSDK 的使用方式
因为这个jssdk被uni-app坑了好多天,作者说支持1.4版本,但是我用1.4的两个分享的新方法一直不支持. 最后只能放弃了,期待什么时候能更新上. 基本的使用方法:第一步 - 下载使用方式下载地 ...