luoguP3431 [POI2005]AUT-The Bus
安利系列博文
https://www.cnblogs.com/tyner/p/11565348.html
https://www.cnblogs.com/tyner/p/11605073.html
做个小总结
树状数组二维数点的特征:
- 矩阵(假设x轴从左到右,y轴从下到上)
- 是树状数组可以维护的
能用树状数组的要求 :
- 维护的东西要有前缀性(说人话:比如我们平常用它来维护的前缀和,就有前缀性(这不是废话么,
- 如果是求任意区间的信息,它要有可减性(因为我们是运用前缀性求得的任意区间)(说人话:我们求区间[l,r]的和,用[1, r]减去[1, l-1]的信息即可
https://www.luogu.org/problem/P3431
可是这题是要维护的是max
, 即二维数max
,这max
和min
一样,都木有可减性
所以树状数组本来是不支持修改和维护max(min)的
但这题的每次修改都只会使原值越来越大(越来越小),所以才可以套用,来维护max(min)
(要是可以改得比原值小,显然就不能用树状数组维护了
(但这个貌似也是只能维护左端点为1的最值。。。
#include<cstdio>
#include<algorithm>
using namespace std;
int read() {
char ch = getchar(); int f=1, x=0;
while(ch<'0' || ch>'9') {if(ch=='-') f=-1; ch = getchar();}
while(ch>='0' && ch<='9') {x = x*10+ch-'0'; ch = getchar();}
return x*f;
}
const int MAX = 100000+99;
#define lowbit(x) (x&-x)
int n,m,k;
int tot;
long long t[MAX];
long long f[MAX];//f[i]:第i个车站的最大载人数,则f[i] = max(f[j]) + v[i], a[j].x∈[1, a[i].x]//注意可以等于a[i].x
struct node{
int xx, x, y, v;
}a[MAX];
bool cmp1(node a, node bb) {
return a.xx < bb.xx;
}
bool cmp2(node a, node bb) {
return (a.y<bb.y) || (a.y==bb.y && a.x<bb.x);
}
long long query(int x) {
long long mx = 0;
while(x) mx=max(mx, t[x]), x-=lowbit(x);//.........
return mx;
}
void add(int x, long long v) {//单点修改
while(x <= tot) t[x] = max(t[x], v), x+=lowbit(x);//.....想想树状数组的结构
}
int main() {
n=read(), m=read(), k=read();
for(int i = 1; i <= k; i++) a[i].xx=read(), a[i].y=read(), a[i].v=read();
sort(a+1, a+1+k, cmp1);
tot = 1;
a[1].x = 1;
for(int i = 2; i <= k; i++) {
if(a[i].xx != a[i-1].xx) ++tot;
a[i].x = tot;
}
sort(a+1, a+1+k, cmp2);
for(int i = 1; i <= k; i++) {
f[i] = query(a[i].x) + a[i].v;
add(a[i].x, f[i]);
}
printf("%lld\n", query(tot));//注意,这还要更新 x = tot直线
}
luoguP3431 [POI2005]AUT-The Bus的更多相关文章
- 「BZOJ1537」Aut – The Bus(变形Dp+线段树/树状数组 最优值维护)
网格图给予我的第一反应就是一个状态 f[i][j] 表示走到第 (i,j) 这个位置的最大价值. 由于只能往下或往右走转移就变得显然了: f[i][j]=max{f[i-1][j], f[i][j-1 ...
- bzoj 1537: [POI2005]Aut- The Bus 线段树
bzoj 1537: [POI2005]Aut- The Bus 先把坐标离散化 设f[i][j]表示从(1,1)走到(i,j)的最优解 这样直接dp::: f[i][j] = max{f[i-1][ ...
- BZOJ1537: [POI2005]Aut- The Bus
1537: [POI2005]Aut- The Bus Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 158 Solved: 100[Submit][S ...
- BZOJ 1537: [POI2005]Aut- The Bus(dp + BIT)
对y坐标离散化, 然后按x坐标排序, dp. 一个点(x, y), 设到达这个点接到的最多乘客数为t, 那么t可以用来更新y'>=y的所有点.用树状数组维护最大值. -------------- ...
- 树状数组 二维偏序【洛谷P3431】 [POI2005]AUT-The Bus
P3431 [POI2005]AUT-The Bus Byte City 的街道形成了一个标准的棋盘网络 – 他们要么是北南走向要么就是西东走向. 北南走向的路口从 1 到 n编号, 西东走向的路从1 ...
- 洛谷P3431 [POI2005]AUT-The Bus
P3431 [POI2005]AUT-The Bus 题目描述 The streets of Byte City form a regular, chessboardlike network - th ...
- Bzoj 1537: [POI2005]Aut- The Bus 题解 [由暴力到正解]
1537: [POI2005]Aut- The Bus Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 387 Solved: 264[Submit][S ...
- 洛谷 P3431:[POI2005]AUT-The Bus(离散化+DP+树状数组)
题目描述 The streets of Byte City form a regular, chessboardlike network - they are either north-south o ...
- bzoj 1537 [POI2005]Aut- The Bus(DP+BIT)
[题意] 顺序经过k个点,求获得的最大权值和. [思路] 设f[i]表示到第i个点,则有转移式: f[i]=min{ f[j]+w[i] } x[j]<=x[i],y[j]<=y[i] 满 ...
随机推荐
- LogMiner Utility Release 8i - 11g (Doc ID 291686.1)
LogMiner Utility Release 8i - 11g (Doc ID 291686.1) APPLIES TO: Oracle Database Exadata Cloud Machin ...
- s3c2440裸机-UART编程(二、UART编程实现)
UART编程 1.初始化 我们的2440支持3个UART串口,以uart0为例讲解. 那么我们需要实现以下这几个函数完成串口的最基本功能: (1)uart0_init()用于初始化串口 (2)putc ...
- new String(request.getParameter("userID").trim().getBytes("8859_1"))的含义是什么?
new String(request.getParameter("userID").trim().getBytes("8859_1")) request.get ...
- Deepin 15.9系统直接运行exe运行程序
以下为你介绍在深度Deepin 15.9 Linux操作系统下直接运行exe文件的方法,此方法基于deepin-wine实现,经测试,一些exe文件是可以正常打开的,但部分可能会出现无法使用的情况,但 ...
- day94_11_26爬虫find与findall
一.使用json 正常的,如果需要将response结果序列化,需要将结果json.loads res1=json.loads(response.text) 但是这样会很麻烦,request提供了js ...
- linux下通过命令行把文件拷贝到U盘上
常用linux,往U盘拷贝文件是常用的一种方法.下面这个方法是笔者亲测有效,暂时记录下来. 1.插入U盘,fdisk -l查看U盘是哪个设备(比如/dev/sdb1)然后mount /dev/sdb ...
- POJ 1724 (分层图最短路)
### POJ 1724 题目链接 ### 题目大意: 给你 N 个点 ,M 条有向路,走每条路需要花费 C 元,这段路的长度为 L . 给你 K 元,问你能否从 1 走到 N 点且花费不超过 K 元 ...
- redis集群之Cluster
RedisCluster 是 Redis 的亲儿子,它是 Redis 作者自己提供的 Redis 集群化方案. 相对于 Codis 的不同,它是去中心化的,如图所示,该集群有三个 Redis 节点组成 ...
- 前端之jquery2
jquery属性操作 1.html() 取出或设置html内容 // 取出html内容 var $htm = $('#div1').html(); // 设置html内容 $('#div1').htm ...
- windows环境下安装配置MongoDB
版本选择MongoDB的版本命名规范如:x.y.z: y为奇数时表示当前版本为开发版,如:2.3.0.2.1.1: y为偶数时表示当前版本为稳定版,如:2.0.1.2.2.0: 目前官网上最新的版本为 ...