尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

abc435_f

abc435_f
📅 发布时间:2026/6/19 12:54:14

abc435_f

不理解为什么都不会,其实挺简单的。

思路

首先,猫一开始在最高点,考虑我下一步有意义的操作只有撤掉最高的塔(若撤掉别的塔,对猫没有任何影响,只会减小答案)。

考虑撤掉 \([l,r]\) 最高塔(位置\(P\))后的两种情况

  • 猫跳到左边最高塔(位置\(p_l\)),这步跳跃对答案贡献 \(del_l=(P-p_l)\) 。
  • 猫跳到右边最高塔(位置\(p_r\)),这步跳跃对答案贡献 \(del_r=(p_r-P)\) 。

那么此时的答案 \(solve(l,r)\) 就是 \(\max(solve(l,P)+del_l, solve(P,r)+del_r)\) 从 \(solve(1,n)\) 开始递归即可。

那么我们只需要快速处理任意一段区间的最大值即可,考虑倍增维护,于是复杂度为预处理 \(O(n\log(n))\) ,计算 \(O(n)\) 显然正确。

Code

// By wnn
#include<bits/stdc++.h>
// simple name
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pque priority_queue
#define x1 x_1
#define y1 y_1
#define fir first
#define sec second
#define pb push_back
#define myfreopen freopen(".in", "r", stdin),freopen(".out", "w", stdout)
// function
#define ls(x) (x << 1)
#define rs(x) ((x << 1) | 1)
#define mid(l, r) ((l + r) >> 1)
#define debug(x) cerr << x << endl
#define dist(x, y, x2, y2) sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2))
#define WA cerr << "Wrong Answer" << endl
#define init_inf32(x) memset(x, 0x3f, sizeof(x))
#define init_inf64(x) memset(x, 0x3fll, sizeof(x))
#define init_0(x) memset(x, 0, sizeof(x))
#define Dec(x) fixed << setprecision(x)
// val
#define eps 1e-9
#define inf32 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3fll
#define mod1 (int)(1e9 + 7)
#define mod2 998244353
#define PI acos(-1.0)
// god
#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// Def important function
inline void init();
inline void ever_init();
inline void solve();
// Init rnd()
mt19937 rnd(time(0) ^ clock());
// Constants
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const int N = 2e5 + 5;int n, p[N], pos[N];
int f[N][20];
inline void init1(){for(int i = 1; i <= n; i++){f[i][0] = p[i];}for(int j = 1; (1 << j) <= n; j++)for(int i = 1; i + (1 << j) - 1 <= n; i++){f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);}
}
inline int cal(int l, int r){int k = (log2(r - l + 1));return max(f[l][k], f[r - (1 << k) + 1][k]);
}
inline int dfs(int l, int r){if(l >= r) return 0;int maxn = cal(l, r), mp = pos[maxn];int len1 = mp - pos[cal(l, mp - 1)], len2 = pos[cal(mp + 1, r)] - mp;return max(dfs(l, mp - 1) + len1, dfs(mp + 1, r) + len2);
}inline void init(){cin >> n;for(int i = 1; i <= n; pos[p[i]] = i, i++) cin >> p[i];init1();cout << dfs(1, n);
}
inline void ever_init(){}
inline void solve(){}signed main(){
//    myfreopen;ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);init();int T = 1;
//    cin >> T;while(T--){ever_init();solve();}return 0;
}
/*things to check:
* Will it MLE?
* Is array big enough?
* Do you need long long?
* Is inf big enough?
* max or min?
* Yes,No or YES,NO?
* Is there anything extra to output?
* Did you Countershoot?
* Have you measured the limit data?
* More measurements should be cleared!!!
*/

相关新闻

  • 记CACC 2025区域赛
  • Ubuntu下,MySQL查询报错sql_mode=only_full_group_by
  • 深入解析:Chrome插件:实现Axure RP HTML原型的便捷预览

最新新闻

  • Kafka集群管理利器:Offset Explorer 3.0 核心功能实战解析
  • 2026年铝方通厂家推荐排行榜:东莞木纹铝方通/异形铝方通/铝方通吊顶/质感现代高性价比厂家精选 - 品牌发掘
  • 硬件设计-PLL篇(下):从理论到实战的性能调优
  • 基于深度学习yolov8的智能车牌识别系统设计1(设计源文件+万字报告+讲解)(支持资料、图片参考_降重降ai)
  • 上海本地贵金属流通规则,2026 黄金回收各类附加损耗明细讲解 - 奢侈品回收测评
  • 3分钟掌握Reflex框架:用纯Python构建全栈Web应用

日新闻

  • 5分钟掌握Python进化算法:Geatpy高性能优化工具完全指南
  • Microchip 24AA044 EEPROM选型与应用全指南:从参数解析到实战编程
  • 华为的鸿蒙到底有多牛?为什么称作遥遥领先?

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号