[zoj3632]线段树的应用
题意:f[i] = min(f[i+L]~f[i+R]) + x,计算f数组。从大到小计算即可,用线段树维护一下。
#pragma comment(linker, "/STACK:10240000,10240000") #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define rep(a, b) for (int a = 0; a < b; a++)
#define rrep(a, b) for (int a = (b - 1); a >= 0; a--)
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
#define pc(a) putchar(a)
#define ps(a) printf("%s", a)
#define pd(a) printf("%d", a)
#define sd(a) scanf("%d", &a) typedef double db;
typedef long long LL;
typedef pair<int, int> pii;
typedef multiset<int> msi;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int, int> mii; const int dx[] = {, , , -, , , -, -};
const int dy[] = {, , -, , -, , , -};
const int maxn = * 1e4 + ;
const int maxm = 1e5 + ;
const int minv = 1e7 + ;
const int max_val = 1e6 + ;
const int MD = 1e9 +;
const LL INF = 1e15;
const double PI = acos(-1.0);
const double eps = 1e-; template<class T> T gcd(T a, T b) { return b == ? a : gcd(b, a % b); } struct SegTree {
LL minv[maxn << ];
void build(int l, int r, int rt) {
minv[rt] = INF;
if (l == r) return ;
define_m;
build(lson);
build(rson);
}
LL get(int L, int R, int l, int r, int rt) {
if (L <= l && r <= R) return minv[rt];
define_m;
LL res = INF;
if (L <= m) res = min(res, get(L, R, lson));
if (R > m) res = min(res, get(L, R, rson));
return res;
}
void update(int p, LL x, int l, int r, int rt) {
if (l == r) {
minv[rt] = x;
return ;
}
define_m;
if (p <= m) update(p, x, lson);
else update(p, x, rson);
minv[rt] = min(minv[rt << ], minv[rt << | ]);
}
}; SegTree st;
int cost[maxn], len[maxn];
int main() {
//freopen("in.txt", "r", stdin);
int n;
while (cin >> n) {
rep(i, n) sd(cost[i]);
rep(i, n) sd(len[i]);
st.build(, n, );
rrep(i, n) {
LL x = cost[i];
if (i + len[i] < n) x += st.get(i + , i + + len[i], , n, );
st.update(i + , x, , n, );
}
cout << st.get(, , , n, ) << endl;
}
return ;
}
[zoj3632]线段树的应用的更多相关文章
- bzoj3932--可持久化线段树
题目大意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第 ...
- codevs 1082 线段树练习 3(区间维护)
codevs 1082 线段树练习 3 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...
- codevs 1576 最长上升子序列的线段树优化
题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...
- codevs 1080 线段树点修改
先来介绍一下线段树. 线段树是一个把线段,或者说一个区间储存在二叉树中.如图所示的就是一棵线段树,它维护一个区间的和. 蓝色数字的是线段树的节点在数组中的位置,它表示的区间已经在图上标出,它的值就是这 ...
- codevs 1082 线段树区间求和
codevs 1082 线段树练习3 链接:http://codevs.cn/problem/1082/ sumv是维护求和的线段树,addv是标记这歌节点所在区间还需要加上的值. 我的线段树写法在运 ...
- PYOJ 44. 【HNSDFZ2016 #6】可持久化线段树
#44. [HNSDFZ2016 #6]可持久化线段树 统计 描述 提交 自定义测试 题目描述 现有一序列 AA.您需要写一棵可持久化线段树,以实现如下操作: A v p x:对于版本v的序列,给 A ...
- CF719E(线段树+矩阵快速幂)
题意:给你一个数列a,a[i]表示斐波那契数列的下标为a[i],求区间对应斐波那契数列数字的和,还要求能够维护对区间内所有下标加d的操作 分析:线段树 线段树的每个节点表示(f[i],f[i-1])这 ...
- 【BZOJ-3779】重组病毒 LinkCutTree + 线段树 + DFS序
3779: 重组病毒 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 224 Solved: 95[Submit][Status][Discuss] ...
- 【BZOJ-3673&3674】可持久化并查集 可持久化线段树 + 并查集
3673: 可持久化并查集 by zky Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 1878 Solved: 846[Submit][Status ...
随机推荐
- mysql数据库深入学习
mysql 数据库 一.数据库介绍 1.关系型数据库的特点 二维表 典型产品Oracle传统企业,MySQL是互联网企业 数据存取是通过SQL 最大特点,数据安全性方面强(ACID) 2.NoSQ ...
- JDBC 工具类封装
每次使用jdbc 我们都要 加载驱动类 创建链接 创建Statement 接口对象执行sql 关闭资源 按照这样的套路可以封装一些重用代码方便在其他方法中调用 package com.xzlf.jdb ...
- ambarella H2平台fpga捕捉卡驱动案例
公司最近开发的一款产品用到了ambarella H2平台的一款Soc,众所周知ambarella的H2系列的Soc编码能力很强,最高可达4kp60,捕捉上没有用ambarella开发板推荐的几个捕捉卡 ...
- 高德地图首席科学家任小枫QA答疑汇总丨视觉+地图技术有哪些新玩法?
上周,阿里巴巴高德地图首席科学家任小枫在#大咖学长云对话#的在线直播活动上就计算机视觉相关技术发展以及在地图出行领域的应用与大家做技术交流,直播间互动火爆,尤其在QA环节,学弟学妹们纷纷就感兴趣的视觉 ...
- 作业九——DFA最小化,语法分析初步
- 数据挖掘入门系列教程(十一)之keras入门使用以及构建DNN网络识别MNIST
简介 在上一篇博客:数据挖掘入门系列教程(十点五)之DNN介绍及公式推导中,详细的介绍了DNN,并对其进行了公式推导.本来这篇博客是准备直接介绍CNN的,但是想了一下,觉得还是使用keras构建一个D ...
- Docker安装MySql完整教程、实操
docker:官网 docker:镜像官网: 镜像官网可以所有应用,选择安装环境:会给出安装命令,例如:docker pull redis 默认拉取最新的版本(指定版本:docker p ...
- DM 源码阅读系列文章(六)relay log 的实现
2019独角兽企业重金招聘Python工程师标准>>> 作者:张学程 本文为 DM 源码阅读系列文章的第六篇,在 上篇文章 中我们介绍了 binlog replication 处理单 ...
- 图论--2-SAT--POJ Ikki's Story IV - Panda's Trick
Description liympanda, one of Ikki's friend, likes playing games with Ikki. Today after minesweeping ...
- 洛谷P1122 最大子树和 树形DP初步
小明对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题.一天他早晨骑车去上课,路上见到一个老伯正在修剪花花草草,顿时想到了一个有关修剪花卉的问题.于是当日课后,小明就向老师提 ...