给你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. 一文彻底理解IO多路复用

    在讲解IO多路复用之前,我们需要预习一下文件以及文件描述符. 什么是文件 程序员使用I/O最终都逃不过文件. 因为这篇同属于高性能.高并发系列,讲到高性能.高并发就离不开Linux/Unix,因此这里 ...

  2. python3实现计算器

    实验内容 1.简单计算器的设计 请设计简单的"加减乘除"计算器并从键盘上输入数据进行计算 数字的加减乘除,input返回的结果是str类型的,通过截取字符串中的运算符,来提取数字, ...

  3. Spring MVC 接收 LocalDate、LocalTime 和 LocalDateTime Java 8 时间类型参数

    使用 Spring MVC 时,很多业务场景下 Controller 需要接收日期时间参数.一个简单的做法是使用 String 接收日期时间字符串(例如:2020-01-29),然后在代码中将其转换成 ...

  4. iptables自动屏蔽访问网站最频繁的IP

    iptables自动屏蔽访问网站频繁的IP 屏蔽每分钟访问超过200的IP 方法1:根据访问日志(Nginx为例 #!/bin/bash DATE=$(date +%d/%b/%Y:%H:%M) AB ...

  5. pycharm工具的使用

    一.Pycharm常用快捷键 快捷键 作用 备注  ctrl + win + 空格  自动提示并导包  连按两次  ctrl + alt + 空格  自动提示并导包  连按两次  Alt + Ente ...

  6. Ajax编程基础

    目录 Ajax编程基础 传统网站中存在的问题 Ajax概述 Ajax的应用场景 Ajax的运行环境 Ajax运行原理及实现 Ajax运行原理 Ajax的实现步骤 1.创建Ajax对象 2.告诉Ajax ...

  7. selenium浏览器弹出框alert 操作

    1.简介 在WebDriver中要处理JS生成的alert.confirm以及prompt,需要 switch_to.alert() 来选取(定位)警告弹窗,在对弹窗进行关闭.输入等信息操作. 2.操 ...

  8. PC端微信多开方式.bat(Windows批处理文件)

    start 微信安装路径\WeChat.exe start 微信安装路径\WeChat.exe

  9. protoc-gen-validate (PGV)

    https://github.com/envoyproxy/protoc-gen-validate This project is currently in alpha. The API should ...

  10. (转载)微软数据挖掘算法:Microsoft 目录篇

    本系列文章主要是涉及内容为微软商业智能(BI)中一系列数据挖掘算法的总结,其中涵盖各个算法的特点.应用场景.准确性验证以及结果预测操作等,所采用的案例数据库为微软的官方数据仓库案例(Adventure ...