当前位置: 首页 > news >正文

天天爱打卡

不是很难的题.下面讲讲我的思考过程.

首先我看到 \(m\) 很小,类比到之前一道 AT 的题,\(dp_i\) 表示考虑到前 \(i\) 个挑战的最大值,然后推式子,开两颗线段树维护,但是这样似乎无法维护区间的包含关系,即只能做特殊性质 BC.

注:@WrongAnswer_90 说其实是可以过的,但是实现比较麻烦,具体可以看this(/bx/bx)

认为这个假了之后,我就不会了...看了题解后才发现原来可以把状态设计成 \(f_{i,0}\) 表示前 \(i\) 天,第 \(i\) 天不跑的最大收益,\(f_{i,1}\) 表示前 \(i\) 天第 \(i\) 天跑的收益,显然

\[f_{i,0}=\max\limits_{j=1}^i f_{j,1} \]

\[f_{i,1}=\max\limits_{j=i-k}^{i-1} f_{i,0}-(i-j)\times d+calc(j,i) \]

其中 \(calc(x, y)\) 表示 \(x + 1\)\(y\) 连续跑能完成的挑战获得的能量值之和。这个可以双指针完成,动态地给 \([0,l_p-1]\) 区间加上 \(v_p\).另外 \(-(i-j) \times d\) 也可以动态,每次区间 \(-d\) 即可。

当前时间复杂度为 \(\mathcal{O}(n \log n)\),考虑优化,发现决策点(\(i\)\(j\))只会为 \(l_i-1\)\(r_i\),离散化即可,但是上面的动态修改要稍作改动。

时间复杂度 \(\mathcal{O}(m \log m)\)

Code:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, mod = 998244353;
const long long inf = -(1ll << 60);
typedef long long ll;
typedef pair<int, int> pii;
void cmax(ll &x, ll y) { if (x < y) x = y; }
void cmin(int &x, int y) { if (x > y) x = y; } 
void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void mul(int &x, int y) { x = 1ll * x * y % mod; }
template<typename T>
void dbg(const T &t) { cerr << t << endl; }
template<typename Type, typename... Types>
void dbg(const Type& arg, const Types&... args) {#ifdef ONLINE_JUDGEreturn ;#endifcerr << arg << ' ';dbg(args...);
}   
int C, T, n, m, k, d, c[N << 1], tot;
struct Event {int l, r, v;bool operator < (const Event &A) const {return r < A.r;}
} a[N];
struct SegTree {#define ls(x) (x << 1)#define rs(x) ((x << 1) | 1)ll tree[N << 3], tag[N << 3]; //N << 1 << 2 void pushup(int pos) { tree[pos] = max(tree[ls(pos)], tree[rs(pos)]); }void pushdown(int pos) {if (tag[pos]) {ll &t = tag[pos];tree[ls(pos)] += t, tree[rs(pos)] += t;tag[ls(pos)] += t, tag[rs(pos)] += t;t = 0;}}void build(int l = 0, int r = tot - 1, int pos = 1) {tree[pos] = 0ll, tag[pos] = 0ll;if (l == r) {return ;}int mid = (l + r) >> 1;build(l, mid, ls(pos)); build(mid + 1, r, rs(pos));pushup(pos);}void modify(int x, int y, ll v, int l = 0, int r = tot - 1, int pos = 1) {if (x <= l && r <= y) {tree[pos] += v;tag[pos] += v;return ;}pushdown(pos);int mid = (l + r) >> 1;if (x <= mid) modify(x, y, v, l, mid, ls(pos));if (mid < y) modify(x, y, v, mid + 1, r, rs(pos));pushup(pos);}ll query(int x, int y, int l = 0, int r = tot - 1, int pos = 1) {if (x <= l && r <= y) return tree[pos];int mid = (l + r) >> 1;pushdown(pos);ll ans = 0;if (x <= mid) ans = max(ans, query(x, y, l, mid, ls(pos)));if (mid < y) ans = max(ans, query(x, y, mid + 1, r, rs(pos)));return ans; }
} st;
int main() {scanf("%d%d", &C, &T);while (T--) {tot = 0;scanf("%d%d%d%d", &n, &m, &k, &d);for (int i = 1; i <= m; i++) {scanf("%d%d%d", &a[i].r, &a[i].l, &a[i].v);a[i].l = a[i].r - a[i].l + 1 - 1;c[++tot] = a[i].l, c[++tot] = a[i].r;}sort(c + 1, c + tot + 1);tot = unique(c + 1, c + tot + 1) - (c + 1);st.build();for (int i = 1; i <= m; i++) {a[i].l = lower_bound(c + 1, c + tot + 1, a[i].l) - c;a[i].r = lower_bound(c + 1, c + tot + 1, a[i].r) - c;}sort(a + 1, a + m + 1);ll ans = 0;for (int i = 1, j = 1; i <= tot; i++) {st.modify(0, i - 1, -1ll * (c[i] - c[i - 1]) * d);while (j <= m && a[j].r == i) {st.modify(0, a[j].l, a[j].v), j++;}cmax(ans, st.query(lower_bound(c + 1, c + tot + 1, c[i] - k) - c, i - 1));if (i + 1 < tot) st.modify(i + 1, i + 1, ans);}	printf("%lld\n", ans);}return 0;
}
http://www.zskr.cn/news/116278.html

相关文章:

  • 数论基础
  • 科技赋能精准种植 水肥一体化激活粮食产能新引擎
  • 2025智能垃圾分类数据集深度解析与实战应用
  • 贪吃蛇
  • Hooks-Admin终极指南:快速搭建现代化后台管理系统
  • VSCode集成Jupyter量子计算实战指南(量子模拟内核全解密)
  • 2026数字经济定调:数据要素成核心引擎,可信数据空间建设引行业升级
  • 如何在30分钟内完成量子电路的高精度VSCode可视化渲染?
  • 被低估的前置语音技术——为什么你的语音 AI 总「听不清」?一篇文章讲清楚 3A、VAD 和声纹识别丨社区来稿
  • 2025年高口碑十大NMN抗衰产品评测,NMN哪个牌子最靠谱?深度解析NMN牌子 - 资讯焦点
  • 2025年喷雾型聚合氯化铝厂商权威推荐榜单:工业级聚合氯化铝/聚合氯化铝絮凝剂/聚合氯化铝源头厂商精选 - 品牌推荐官
  • PLC通讯编程系列之一,为什么复位发送请求信号要在发送块的前面?
  • 长沙GEO优公司,ai搜索推广,让企业节省80%的广告费 - 舆通Geo
  • 一键部署EmotiVoice:Docker镜像使用指南
  • 2025恒温恒湿试验箱年终大盘点:国货崛起,如何选择最适合你的品牌? - 品牌推荐大师1
  • 可信数据空间能给企业和个人带来什么?2026政策下的新机遇
  • 2025年山东软件项目验收测试报告服务商权威推荐榜单:山东安全渗透性测试/山东系统验收报告/山东第三方软件测试资质机构精选 - 品牌推荐官
  • 176. 第二高的薪水
  • 如何从零开始打造你的第一台四足机器人:Mini Pupper完全实战手册
  • Windows Terminal:一站式多设备远程管理终极解决方案
  • 从“监控”到“可观测”:2025年主流IT监控系统架构演进与选型建议
  • Element Plus自动化部署终极指南:从零到一的完整指南
  • Feishin音乐播放器:为什么它是最佳的自托管音乐解决方案?
  • 智能内容本地化革命:打造永久收藏的数字宝库
  • 量子计算结果不稳定?你必须知道的VSCode+Jupyter 7个调试秘籍
  • 三分钟带你掌握Function Calling
  • 【linux期末大作业】在Ubuntu22.04上通过XQUME安装RISC-V架构的linux系统并写hello world进行测试
  • 你还在手动调试量子代码?VSCode自动化性能分析实战详解
  • 【开题答辩全过程】以 基于SSM的考研信息共享平台为例,包含答辩的问题和答案
  • 【VSCode量子开发插件集成指南】:掌握未来编程的5大核心工具