给你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. JMeter如何设置语言为中文

    一.现象 JMeter安装后,默认语言为英文,如下图所示: 对于英文水平一般的人来说,刚开始使用起来比较费劲(比如我),影响我工作效率.那么,怎么将英文改为中文呢? 二.解决方法 1.修改设置 点击菜 ...

  2. LeetCode解题Golang(1-10)

    前言 LeetCode题目个人答案(Golang版) 本篇预期记录 1-10 题, 持续更新 正文 1.两数之和(简单) https://leetcode-cn.com/problems/two-su ...

  3. web渗透之常见shell反弹姿势

    常见反弹shell总结: 原文链接请点击:https://ruoli-s.github.io/posts/b956.html 一.bash反弹 通用 ① 在kali机里面开启端口监听: nc -lvv ...

  4. Java类的加载过程-重点!!

    java类的加载过程有以下几步共同完成: 加载->连接->初始化.连接又分为验证.准备.解析 一个非数组类的加载阶段(加载阶段获取类的二进制字节流的动作)是可控性最强的阶段,这一步我们可以 ...

  5. MySQL多版本并发控制——MVCC机制分析

    MVCC,即多版本并发控制(Multi-Version Concurrency Control)指的是,通过版本链维护一个数据的多个版本,使得读写操作没有冲突,可保证不同事务读写.写读操作并发执行,提 ...

  6. 使用K8s的一些经验和体会

    坑 Java应用程序的奇怪案例 ​ 在微服务和容器化方面,工程师倾向于避免使用 Java,这主要是由于 Java 臭名昭著的内存管理.但是,现在情况发生了改变,过去几年来 Java 的容器兼容性得到了 ...

  7. gears-绕过rbash

    0x00 信息收集 0x01 smb攻击 crunch 生成密码的一个软件 @%%,这个是给的密码参数. crunch 4 4 -t @%%, -o words 最小4位,最长 4位 fcrackzi ...

  8. ABAP 多表联合查询

    inner join(等值连接) 只返回两个表中联结字段相等的行left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录right join(右联接) 返回包括右表中的所有记录 ...

  9. Nginx基础环境搭建

    1.下载docker toolbox https://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/ 2.选择好安装目录 一路nex ...

  10. python爬虫如何提高效率

    开启线程池: 线程池 asyncio 特殊的函数 协程 任务对象 任务对象绑定 事件循环 from multiprocessing.dummy import Pool map(func,alist): ...