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|,而是求每个元素属于子 ...
随机推荐
- 【1w字+干货】第一篇,基础:让你的 Redis 不再只是安装吃灰到卸载(Linux环境)
Redis 基础以及进阶的两篇已经全部更新好了,为了字数限制以及阅读方便,分成两篇发布. 本篇主要内容为:NoSQL 引入 Redis ,以及在 Linux7 环境下的安装,配置,以及总结了非常详细的 ...
- ryu—交换机
1. 代码解析 ryu/app/example_switch_13.py: from ryu.base import app_manager from ryu.controller import of ...
- scrapy-redis非多网址采集的使用
问题描述 默认RedisSpider在启动时,首先会读取redis中的spidername:start_urls,如果有值则根据url构建request对象. 现在的要求是,根据特定关键词采集. 例如 ...
- GraphQL两年实战
https://mp.weixin.qq.com/s/XIQ-0kRhjCe2ubBuhnhlQA
- (Oracle)DDL及其数据泵导入导出(impdp/expdp)
create tablespace ybp_dev datafile 'G:\app\Administrator\oradata\health\ybp_dev1.dbf' size 10m autoe ...
- 8.3 Customizing Git - Git Hooks 钩子 自动拉取 自动部署 提交工作流钩子,电子邮件工作流钩子和其他钩子
https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks https://github.com/git/git/blob/master/temp ...
- Java反序列化: 基于CommonsCollections4的Gadget分析 Java 序列化与反序列化安全分析
Java反序列化: 基于CommonsCollections4的Gadget分析 welkin 京东安全 5天前 https://mp.weixin.qq.com/s/OqIWUsJe9XV39SPN ...
- 在不同情况下connect失败和ping不通的数据分析
- UML 博客学习 后续继续完善
http://blog.csdn.net/monkey_d_meng/article/details/6005764 http://blog.csdn.net/badobad/article/det ...
- Linux命令之Crontab定时任务,利用Crontab定时执行spark任务
Linux命令之Crontab定时任务,利用Crontab定时执行spark任务 一.Linux命令之Crontab定时任务 1.1 常见Crontab任务 1.1.1 安装crontab 1.1.2 ...