题解 - C F 1364 B \mathrm{CF1364B} CF1364B

题目意思

  • 题目传送门

S o l \mathrm{Sol} Sol

  • 首先我们考虑一个性质,如何才能使得贡献尽量大。画几个图看看

对于第一种一条直线类型的它的实际贡献就是 ∣ c − a ∣ |c-a| ∣c−a∣,而对于第二种它的贡献就为 ∣ a − d ∣ + ∣ d − b ∣ + . . . ∣ c − e ∣ |a-d|+|d-b|+...|c-e| ∣a−d∣+∣d−b∣+...∣c−e∣。发现能产生贡献的情况就是那种峰,谷的情况,于是我们记录这些拐点即可。时间复杂度 O ( n ) O(n) O(n)

C o d e \mathrm{Code} Code

#include <bits/stdc++.h>
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
#define Dow(i,b,a) for ( int i=(b);i>=(a);i-- )
#define GO(i,x) for ( int i=head[x];i;i=e[i].nex )
#define mem(x,s) memset(x,s,sizeof(x))
#define cpy(x,s) memcpy(x,s,sizeof(x))
#define YES return puts("YES"),0
#define NO return puts("NO"),0
#define GG return puts("-1"),0
#define pb push_back
using namespace std;inline int read()
{int sum=0,ff=1; char ch=getchar();while(!isdigit(ch)){if(ch=='-') ff=-1;ch=getchar();}while(isdigit(ch))sum=sum*10+(ch^48),ch=getchar();return sum*ff;
}const int mod=1e9+7;
const int mo=998244353;
const int N=1e5+5;int n,m,Q,a[N],b[N],ans;int main()
{Q=read();For(q,1,Q){n=read();For(i,1,n) a[i]=read();b[m=1]=1;For(i,2,n-1) if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1])) b[++m]=i;b[++m]=n;printf("%d\n",m);For(i,1,m) printf("%d ",a[b[i]]);puts("");}return 0;
}

题解 CF1364B Most socially-distanced subsequence相关推荐

  1. opencv图像深度-1_OpenCV空间AI竞赛之旅(第1部分-初始设置+深度)

    opencv图像深度-1 OpenCV空间AI竞赛 (OpenCV Spatial AI Competition) Recently, the people at OpenCV launched th ...

  2. 苹果iphone 12它只是一个电话

    Electric. That's the atmosphere at an iPhone launch. Seated in one of Apple's exquisite presentation ...

  3. Python干货项目:【新闻急先锋】新闻API获取谷歌头条新闻

    新闻API是用于搜索和检索来自整个Web的实时新闻文章,可以根据某些标准检索新闻. 使用它,可以获取任何新闻网站上运行的顶级新闻,也可以搜索特定主题(或关键字)的顶级新闻. 假设要搜索的主题(关键字) ...

  4. 实施一个光明与黑暗的主题,以持久的React

    介绍(Introduction) So, you've come to that point in the creation of your website where you want to do ...

  5. 两个词之间的依存语义关系_相互依存的网络之间的级联中断-2003年停电的5个教训

    两个词之间的依存语义关系 In 2003, what should have been a local power outage resulted in 50 million people losin ...

  6. 语料库建立_通过挖掘covid 19科学语料库建立对病毒的理解

    语料库建立 At the time I publish this, we are entering the 9th month since COVID-19 froze the world. Sinc ...

  7. 托管和非托管_技术和托管新闻综述

    托管和非托管 Welcome to our latest round-up of news from the technology and hosting world. Here's what we' ...

  8. 蜜蜂编程_没有蜜蜂就无法拼写“可预防”

    蜜蜂编程 The New York Times Spelling Bee is a daily online puzzle that presents a set of seven letters a ...

  9. E.03.31 Shadowed by Pandemic, Olympic Torch Relay Begins in Japan

    2021.03.31 文章目录 [课程导读] [英文原文] [外刊原文] [课程导读] 上周,东京奥运会火炬传递仪式在福岛县正式开启.日本政府将这届因新冠疫情推迟了一年的奥运会视为重建和复兴的标志,认 ...

最新文章

  1. VB.NET中的日期时间转换
  2. 【HDU2683 TCE-frep number system 完全数+二项展开式】
  3. IN-我的生活in记 | 手摸手产品研究院
  4. jQuery同时监听两个事件---实现同时操控两个按键
  5. 【Git】Git解决文件本地更改的合并覆盖错误
  6. hdu 3093 动态规划
  7. C语言之结构体和共用体
  8. python涉及excel_Python实现EXCEL的常规操作,一文涵盖10个方面
  9. 题解(5-8)-----寒假练习赛(一)
  10. php数据库太小要怎么改,PHP入坑之 MySqli对数据库增删改查
  11. 前端请求接口出现415错误
  12. linux学习资料(转帖收藏)
  13. linux常用命令整理(详细)
  14. mysql驱动有什么用_什么是数据库驱动?
  15. 关于MacBook蓝牙键盘鼠标耳机等设备各种的卡顿、黏滞、断开连接等各种问题解决方案
  16. ios 判断手机角度_IOS 判断iPhone刘海屏
  17. 牛客网——华为题库(91~100)
  18. 15.大理石在哪儿(Uv10474)
  19. 秋色园QBlog技术原理解析:系列终结篇:最后的AOP策略(十九)
  20. 研究强调联网汽车的网络风险

热门文章

  1. 安川机器人编辑程序(一)
  2. 小说生成对抗网络GANs
  3. 操作系统、数据库的默认密码
  4. 创建型设计模式-原型模式
  5. 2分钟上手、3小时学会无代码软件开发---日期、时间和计时器
  6. 区块链项目的黑马——NGK超级公链
  7. 俏皮短信(zhuan)
  8. Java下HttpUnit和Jsoup的Http抓取
  9. iPhone 几年换一次比较合?---转自百度新闻|数码千机会
  10. 多线程与高并发(六) 单机压测工具JMH,Disruptor原理解析