题解 CF1364B Most socially-distanced subsequence
题解 - 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相关推荐
- opencv图像深度-1_OpenCV空间AI竞赛之旅(第1部分-初始设置+深度)
opencv图像深度-1 OpenCV空间AI竞赛 (OpenCV Spatial AI Competition) Recently, the people at OpenCV launched th ...
- 苹果iphone 12它只是一个电话
Electric. That's the atmosphere at an iPhone launch. Seated in one of Apple's exquisite presentation ...
- Python干货项目:【新闻急先锋】新闻API获取谷歌头条新闻
新闻API是用于搜索和检索来自整个Web的实时新闻文章,可以根据某些标准检索新闻. 使用它,可以获取任何新闻网站上运行的顶级新闻,也可以搜索特定主题(或关键字)的顶级新闻. 假设要搜索的主题(关键字) ...
- 实施一个光明与黑暗的主题,以持久的React
介绍(Introduction) So, you've come to that point in the creation of your website where you want to do ...
- 两个词之间的依存语义关系_相互依存的网络之间的级联中断-2003年停电的5个教训
两个词之间的依存语义关系 In 2003, what should have been a local power outage resulted in 50 million people losin ...
- 语料库建立_通过挖掘covid 19科学语料库建立对病毒的理解
语料库建立 At the time I publish this, we are entering the 9th month since COVID-19 froze the world. Sinc ...
- 托管和非托管_技术和托管新闻综述
托管和非托管 Welcome to our latest round-up of news from the technology and hosting world. Here's what we' ...
- 蜜蜂编程_没有蜜蜂就无法拼写“可预防”
蜜蜂编程 The New York Times Spelling Bee is a daily online puzzle that presents a set of seven letters a ...
- E.03.31 Shadowed by Pandemic, Olympic Torch Relay Begins in Japan
2021.03.31 文章目录 [课程导读] [英文原文] [外刊原文] [课程导读] 上周,东京奥运会火炬传递仪式在福岛县正式开启.日本政府将这届因新冠疫情推迟了一年的奥运会视为重建和复兴的标志,认 ...
最新文章
- VB.NET中的日期时间转换
- 【HDU2683 TCE-frep number system 完全数+二项展开式】
- IN-我的生活in记 | 手摸手产品研究院
- jQuery同时监听两个事件---实现同时操控两个按键
- 【Git】Git解决文件本地更改的合并覆盖错误
- hdu 3093 动态规划
- C语言之结构体和共用体
- python涉及excel_Python实现EXCEL的常规操作,一文涵盖10个方面
- 题解(5-8)-----寒假练习赛(一)
- php数据库太小要怎么改,PHP入坑之 MySqli对数据库增删改查
- 前端请求接口出现415错误
- linux学习资料(转帖收藏)
- linux常用命令整理(详细)
- mysql驱动有什么用_什么是数据库驱动?
- 关于MacBook蓝牙键盘鼠标耳机等设备各种的卡顿、黏滞、断开连接等各种问题解决方案
- ios 判断手机角度_IOS 判断iPhone刘海屏
- 牛客网——华为题库(91~100)
- 15.大理石在哪儿(Uv10474)
- 秋色园QBlog技术原理解析:系列终结篇:最后的AOP策略(十九)
- 研究强调联网汽车的网络风险