2019牛客多校第一场I Points Division(DP)题解
题意:
n个点,分成两组A,B,如果点i在A中,那么贡献值\(a_i\),反之为\(b_i\)。
现要求任意\(i \in A,j \in B\)不存在 \(x_i >= x_j\) 且 \(y_i <= y_j\),也就是说A中点不在B中点的右下方。
思路:
https://blog.nowcoder.net/n/7205418146f3446eb0b1ecec8d2ab1da
代码:
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5 + 5;
const int M = 50 + 5;
const ull seed = 131;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
struct Node{
int x, y, a, b;
}p[maxn];
bool cmp(Node x, Node y){
if(x.x == y.x) return x.y > y.y;
return x.x < y.x;
}
vector<int> vv;
ll Max[maxn << 2], lazy[maxn << 2];
void pushup(int rt){
Max[rt] = max(Max[rt << 1], Max[rt << 1 | 1]);
}
void pushdown(int rt){
if(lazy[rt]){
lazy[rt << 1] += lazy[rt];
lazy[rt << 1 | 1] += lazy[rt];
Max[rt << 1] += lazy[rt];
Max[rt << 1 | 1] += lazy[rt];
lazy[rt] = 0;
}
}
void build(int l, int r, int rt){
Max[rt] = lazy[rt] = 0;
if(l == r) return;
int m = (l + r) >> 1;
build(l, m, rt << 1);
build(m + 1, r, rt << 1 | 1);
}
void update(int L, int R, int l, int r, int v, int rt){
if(L > R) return;
if(L <= l && R >= r){
Max[rt] += v;
lazy[rt] += v;
return;
}
pushdown(rt);
int m = (l + r) >> 1;
if(L <= m)
update(L, R, l, m, v, rt << 1);
if(R > m)
update(L, R, m + 1, r, v, rt << 1 | 1);
pushup(rt);
}
void change(int pos , int l, int r, ll v, int rt){
if(l == r){
Max[rt] = max(Max[rt], v);
return;
}
pushdown(rt);
int m = (l + r) >> 1;
if(pos <= m)
change(pos, l, m, v, rt << 1);
else
change(pos, m + 1, r, v, rt << 1 | 1);
pushup(rt);
}
ll query(int L, int R, int l, int r, int rt){
if(L <= l && R >= r){
return Max[rt];
}
pushdown(rt);
int m = (l + r) >> 1;
ll MAX = -1;
if(L <= m)
MAX = max(MAX, query(L, R, l, m, rt << 1));
if(R > m)
MAX = max(MAX, query(L, R, m + 1, r, rt << 1 | 1));
pushup(rt);
return MAX;
}
int main(){
int n;
while(~scanf("%d", &n)){
vv.clear();
for(int i = 1; i <= n; i++){
scanf("%d%d%d%d", &p[i].x, &p[i].y, &p[i].a, &p[i].b);
vv.push_back(p[i].y);
}
vv.push_back(-1);
sort(vv.begin(), vv.end());
vv.erase(unique(vv.begin(), vv.end()), vv.end());
for(int i = 1; i <= n; i++) p[i].y = lower_bound(vv.begin(), vv.end(), p[i].y) - vv.begin() + 1;
sort(p + 1, p + n + 1, cmp);
build(1, vv.size(), 1);
for(int i = 1; i <= n; i++){
ll tmp = query(1, p[i].y, 1, vv.size(), 1);
update(p[i].y, vv.size(), 1, vv.size(), p[i].b, 1);
update(1, p[i].y - 1, 1, vv.size(), p[i].a, 1);
change(p[i].y, 1, vv.size(), tmp + p[i].b, 1);
}
printf("%lld\n", Max[1]);
}
return 0;
}
2019牛客多校第一场I Points Division(DP)题解的更多相关文章
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 2019牛客多校第一场E ABBA(DP)题解
链接:https://ac.nowcoder.com/acm/contest/881/E 来源:牛客网 ABBA 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语 ...
- 2019牛客多校第一场E ABBA 贪心 + DP
题意:问有多少个有(n + m)个A和(n + m)个B的字符串可以凑出n个AB和m个BA. 思路:首先贪心的发现,如果从前往后扫,遇到了一个A,优先把它看成AB的A,B同理.这个贪心策略用邻项交换很 ...
- 2019牛客多校第一场A-Equivalent Prefixes
Equivalent Prefixes 传送门 解题思路 先用单调栈求出两个序列中每一个数左边第一个小于自己的数的下标, 存入a[], b[].然后按照1~n的顺序循环,比较 a[i]和b[i]是否相 ...
- 2019牛客多校第一场 A.Equivalent Prefixes
题目描述 Two arrays u and v each with m distinct elements are called equivalent if and only if RMQ(u,l,r ...
- 2019 牛客多校第一场 D Parity of Tuples
题目链接:https://ac.nowcoder.com/acm/contest/881/D 看此博客之前请先参阅吕凯飞的论文<集合幂级数的性质与应用及其快速算法>,论文中很多符号会被本文 ...
- 2019牛客多校第一场 E-ABBA(dp)
ABBA 题目传送门 解题思路 用dp[i][j]来表示前i+j个字符中,有i个A和j个B的合法情况个数.我们可以让前n个A作为AB的A,因为如果我们用后面的A作为AB的A,我们一定也可以让前面的A对 ...
- 2019年牛客多校第一场 E题 ABBA DP
题目链接 传送门 思路 首先我们知道\('A'\)在放了\(n\)个位置里面是没有约束的,\('B'\)在放了\(m\)个位置里面也是没有约束的,其他情况见下面情况讨论. \(dp[i][j]\)表示 ...
- 【2019牛客多校第一场】XOR
题意: 给你一个集合A,里边有n个正整数,对于所有A的.满足集合内元素异或和为0的子集S,问你∑|S| n<=1e5,元素<=1e18 首先可以转化问题,不求∑|S|,而是求每个元素属于子 ...
随机推荐
- scrapy框架的中间件
中间件的使用 作用:拦截所有的请求和响应 拦截请求:process_request拦截正常的请求,process_exception拦截异常的请求 篡改请求的头信息 def process_reque ...
- 无法获取 vmci 驱动程序版本: 句柄无效。 驱动程序 vmci.sys 版本不正确。请尝试重新安装 VMware Workstation。 打开模块DevicePowerOn电源失败。
1.别打开电源,然后到虚拟机安装文件夹内.2.找到你的虚拟机系统文件中后缀为vmx的文件,右击用记事本或者Notepad++打开.2.搜索找到vmci0.present='TRUE',字段,把true ...
- Maven 知识点总结以及解决jar报冲突的几种方法
1.常见的命令 Compile Test Package Install Deploy Clean 2.坐标的书写规范 groupId 公司或组织域名的倒序 artifactId 项目名或模块名 ve ...
- CentOS 镜像下载地址
CentOS镜像地址:http://isoredirect.centos.org/altarch/7/isos/i386/
- ValueError: the environment variable is longer than 32767 characters On Windows, an environment variable string ("name=value" string) is limited to 32,767 characters
https://github.com/python/cpython/blob/aa1b8a168d8b8dc1dfc426364b7b664501302958/Lib/test/test_os.py ...
- pull push 监控指标
Prometheus 原理介绍 - 知乎 https://zhuanlan.zhihu.com/p/70090800 Prometheus由Go语言编写而成,采用Pull方式获取监控信息,并提供了多维 ...
- Kubernetes TensorFlow 默认 特定 集群管理器 虚拟化技术
Our goal is to foster an ecosystem of components and tools that relieve the burden of running applic ...
- OIer 生涯绊脚石
字符串 哈希进制搞质数 \({\color{OrangeRed}{KMP}}\) 数组别开太大,否则 \({\color{Gold}{TLE}}\) 没有必要 \({\color{Cyan}{strl ...
- Dos命令思维导图
通过思维导图的方式,总结常用Dos命令. 各种思维导图下载地址
- Nacos服务心跳和健康检查源码介绍
服务心跳 Nacos Client会维护一个定时任务通过持续调用服务端的接口更新心跳时间,保证自己处于存活状态,防止服务端将服务剔除,Nacos默认5秒向服务端发送一次,通过请求服务端接口/insta ...