给你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+线段树优化)的更多相关文章

  1. 2020牛客暑假多校训练营 第二场 H Happy Triangle set 线段树 分类讨论

    LINK:Happy Triangle 这道题很容易. 容易想到 a+b<x a<x<b x<a<b 其中等于的情况在第一个和第三个之中判一下即可. 前面两个容易想到se ...

  2. 2019牛客暑期多校训练营(第二场) H-Second Large Rectangle(单调栈)

    题意:给出由01组成的矩阵,求求全是1的次大子矩阵. 思路: 单调栈 全是1的最大子矩阵的变形,不能直接把所有的面积存起来然后排序取第二大的,因为次大子矩阵可能在最大子矩阵里面,比如: 1 0 0 1 ...

  3. 2019牛客暑期多校训练营(第九场) D Knapsack Cryptosystem

    题目 题意: 给你n(最大36)个数,让你从这n个数里面找出来一些数,使这些数的和等于s(题目输入),用到的数输出1,没有用到的数输出0 例如:3  4 2 3 4 输出:0 0 1 题解: 认真想一 ...

  4. 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题)

    layout: post title: 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题) author: "luowentaoaa" c ...

  5. 2019牛客暑期多校训练营(第一场)A Equivalent Prefixes(单调栈/二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 Two arrays u and v each with m distinct elements ...

  6. 2019牛客暑期多校训练营(第一场)A题【单调栈】(补题)

    链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 题目描述 Two arrays u and v each with m distinct elem ...

  7. 2019牛客暑期多校训练营(第一场) B Integration (数学)

    链接:https://ac.nowcoder.com/acm/contest/881/B 来源:牛客网 Integration 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 5242 ...

  8. 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...

  9. 2019牛客暑期多校训练营(第二场)F.Partition problem

    链接:https://ac.nowcoder.com/acm/contest/882/F来源:牛客网 Given 2N people, you need to assign each of them ...

  10. 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)

    题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9:  对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可.     后者mod=1e9,5才 ...

随机推荐

  1. 【函数分享】每日PHP函数分享(2021-1-8)

    explode() 使用一个字符串分割另一个字符串. array explode( string $delimiter , string $string [, int $limit ]) 参数描述de ...

  2. Linux基础命令整合

    linux基础命令整理 1.系统相关命令 shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdown -h hours:minu ...

  3. 【Git】命令行操作

    Git 命令行操作 1 本地库初始化 git init:初始化本地仓库 效果 注意:.git目录中存放的是本地库相关的子目录和文件,不要删除,也不要胡乱修改. 2 设置签名 形式: 用户名:tom E ...

  4. 【SpringBoot1.x】SpringBoot1.x 启动配置原理 和 自定义starter

    SpringBoot1.x 启动配置原理 和 自定义starter 启动配置原理 本节源码 启动过程主要为: new SpringApplication(sources) 创建 SpringAppli ...

  5. 【Linux】如何查看命令来源于哪个包

    Debian:(Ubuntu等) 先安装apt-file sudo apt-get install -y apt-file apt-file update 查询命令:(已查询ifconfig为例) r ...

  6. LR参数

    一.LR函数 : lr_start_transaction:   为性能分析标记事务的开始 lr_end_transaction: 为性能分析标记事务的结束:事务名称与事务开始时保持一致 lr_ren ...

  7. LeetCode590. N叉树的后序遍历

    题目 1 class Solution { 2 public: 3 vector<int>ans; 4 vector<int> postorder(Node* root) { ...

  8. PHP设计模式之装饰器模式(Decorator)

    PHP设计模式之装饰器模式(Decorator) 装饰器模式 装饰器模式允许我们给一个类添加新的功能,而不改变其原有的结构.这种类型的类属于结构类,它是作为现有的类的一个包装 装饰器模式的应用场景 当 ...

  9. RocketMq消息 demo

    参考 https://blog.csdn.net/asdf08442a/article/details/54882769 整理出来的测试 demo 1.produce 生产者 1 package co ...

  10. perl打开本地/服务器图片

    index.html <html> <body> <h2> perl read img </h2> <img src = "displa ...