2019牛客暑期多校训练营(第一场)I Points Division(dp+线段树优化)
给你n个点,第i个点在的位置为(xi,yi),有两个属性值(ai,bi)。现在让你把这n个点划分为A和B两个部分,使得最后不存在i∈A和j∈B,使得xi>=xj且yi<=yj。然后对于所有的划分方法,找到并输出最大和
现在的疑问点在于为什么要多加一个高度为0的虚拟节点(因为要考虑全是A集合的)
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N = 1e5+7;
const double eps = 1e-8;
const ll mod = 1e9+7;
struct Point{
int x,y;
ll a,b;
friend bool operator < (Point a,Point b){
if(a.x==b.x) return a.y>b.y;
return a.x<b.x;
}
};
Point p[N];
ll h[N];
struct tree{
int l,r;
ll lazy,v;
};
tree t[N<<2];
void build(int p,int l,int r){
t[p]=(tree){l,r,0,0};
if(l==r) return ;
int mid=(l+r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
}
void pushdown(int p){
if(t[p].lazy){
t[p<<1].v+=t[p].lazy;
t[p<<1|1].v+=t[p].lazy;
t[p<<1].lazy+=t[p].lazy;
t[p<<1|1].lazy+=t[p].lazy;
t[p].lazy=0;
}
}
void update(int p,int pos,ll x){
if(t[p].l==t[p].r&&t[p].l==pos){
t[p].v=max(t[p].v,x);
return ;
}
pushdown(p);
int mid=(t[p].l+t[p].r)>>1;
if(pos<=mid) update(p<<1,pos,x);
else update(p<<1|1,pos,x);
t[p].v=max(t[p<<1].v,t[p<<1|1].v);
}
void update1(int p,int l,int r,ll x){
if(l>r) return ;
if(l<=t[p].l&&t[p].r<=r){
t[p].v+=x;
t[p].lazy+=x;
return ;
}
pushdown(p);
int mid=(t[p].l+t[p].r)>>1;
if(l<=mid) update1(p<<1,l,r,x);
if(mid<r) update1(p<<1|1,l,r,x);
t[p].v=max(t[p<<1].v,t[p<<1|1].v);
}
ll query(int p,int l,int r){
if(l>r) return 0;
if(l<=t[p].l&&t[p].r<=r){
return t[p].v;
}
int mid=(t[p].l+t[p].r)>>1;
pushdown(p);
ll res=0;
if(l<=mid) res=max(res,query(p<<1,l,r));
if(mid<r) res=max(res,query(p<<1|1,l,r));
return res;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
while(cin>>n){
int cnt=0;
for(int i=1;i<=n;i++){
cin>>p[i].x>>p[i].y>>p[i].a>>p[i].b;
h[++cnt]=p[i].y;
}
sort(p+1,p+1+n);
sort(h+1,h+1+cnt);
cnt=unique(h+1,h+1+cnt)-(h+1);
for(int i=1;i<=n;i++) p[i].y=lower_bound(h+1,h+1+cnt,p[i].y)-h+1;
cnt++;
build(1,1,cnt);
for(int i=1;i<=n;i++){
ll res=query(1,1,p[i].y);
update(1,p[i].y,res+p[i].b);
update1(1,p[i].y+1,cnt,p[i].b);
update1(1,1,p[i].y-1,p[i].a);
}
cout<<t[1].v<<endl;
}
return 0;
}
2019牛客暑期多校训练营(第一场)I Points Division(dp+线段树优化)的更多相关文章
- 2020牛客暑假多校训练营 第二场 H Happy Triangle set 线段树 分类讨论
LINK:Happy Triangle 这道题很容易. 容易想到 a+b<x a<x<b x<a<b 其中等于的情况在第一个和第三个之中判一下即可. 前面两个容易想到se ...
- 2019牛客暑期多校训练营(第二场) H-Second Large Rectangle(单调栈)
题意:给出由01组成的矩阵,求求全是1的次大子矩阵. 思路: 单调栈 全是1的最大子矩阵的变形,不能直接把所有的面积存起来然后排序取第二大的,因为次大子矩阵可能在最大子矩阵里面,比如: 1 0 0 1 ...
- 2019牛客暑期多校训练营(第九场) D Knapsack Cryptosystem
题目 题意: 给你n(最大36)个数,让你从这n个数里面找出来一些数,使这些数的和等于s(题目输入),用到的数输出1,没有用到的数输出0 例如:3 4 2 3 4 输出:0 0 1 题解: 认真想一 ...
- 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题)
layout: post title: 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题) author: "luowentaoaa" c ...
- 2019牛客暑期多校训练营(第一场)A Equivalent Prefixes(单调栈/二分+分治)
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 Two arrays u and v each with m distinct elements ...
- 2019牛客暑期多校训练营(第一场)A题【单调栈】(补题)
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 题目描述 Two arrays u and v each with m distinct elem ...
- 2019牛客暑期多校训练营(第一场) B Integration (数学)
链接:https://ac.nowcoder.com/acm/contest/881/B 来源:牛客网 Integration 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 5242 ...
- 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)
链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...
- 2019牛客暑期多校训练营(第二场)F.Partition problem
链接:https://ac.nowcoder.com/acm/contest/882/F来源:牛客网 Given 2N people, you need to assign each of them ...
- 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)
题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9: 对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可. 后者mod=1e9,5才 ...
随机推荐
- loj #6179. Pyh 的求和 莫比乌斯反演
题目描述 传送门 求 \(\sum\limits_{i=1}^n\sum\limits_{j=1}^m \varphi(ij)(mod\ 998244353)\) \(T\) 组询问 \(1 \leq ...
- Head First 设计模式 —— 09. 模版方法 (Template Method) 模式
模板方法模式 在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. P289 特点 主导算法框架,并且保护这个算法 P28 ...
- k8s之RBAC授权模式
导读 上一篇说了k8s的授权管理,这一篇就来详细看一下RBAC授权模式的使用 RBAC授权模式 基于角色的访问控制,启用此模式,需要在API Server的启动参数上添加如下配置,(k8s默然采用此授 ...
- 剑指offer之重建二叉树
1.问题描述:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字. 例如输入前序遍历序列pre {1,2,4,7,3,5,6, ...
- springBoot实现redis分布式锁
参考:https://blog.csdn.net/weixin_44634197/article/details/108308395 .. 使用redis的set命令带NX(not exist)参数实 ...
- 【十天自制软渲染器】DAY 02:画一条直线(DDA 算法 & Bresenham’s 算法)
推荐关注公众号「卤蛋实验室」或访问博客原文,更新更及时,阅读体验更佳 第一天我们搭建了 C++ 的运行环境并画了一个点,根据 点 → 线 → 面 的顺序,今天我们讲讲如何画一条直线. 本文主要讲解直线 ...
- 安装newman error:package exports for 'c:\nmp\node_modules\newman\node_module 解决办法
一.场景描述: 通过npm安装newman时,一直失败. 尝试了很多安装命令: npm install -g newman npm install -g newman --registry=http: ...
- bash shell关联数组总结
[原创]本博文为原创博文,引用或转发请注明原始出处和链接:https://www.cnblogs.com/dingbj/p/dict_array.html 什么是关联数组? 关联数组相对于索引数组,又 ...
- python zxing包解析二维码报UnicodeDecodeError错误解决办法
一般错误的原因是这个库不支持中文的解码(二维码内容包含中文). 修改如下: 进入zxing.__init__.py代码中,类BarCode下,parse方法中: 找到下面这两行原代码如下: 1 raw ...
- Junit测试和反射
Junit单元测试 测试分类 黑盒测试:不需要写代码,给输入值,看程序能否得到输出期望值. 白盒测试:需要些代码,关注程序具体的执行流程. Junit的使用 步骤 定义一个测试类(测试用例). 定义测 ...