题意:

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);elsechange(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;
}

转载于:https://www.cnblogs.com/KirinSB/p/11224984.html

2019牛客多校第一场I Points Division(DP)题解相关推荐

  1. 2019牛客多校第一场

    2019牛客多校第一场 题号 题目 知识点 A Monotonic Matrix B Symmetric Matrix C Fluorescent 2 D Two Graphs E Removal F ...

  2. 2019 牛客多校第一场 F Random Point in Triangle

    题目链接:https://ac.nowcoder.com/acm/contest/881/F 题目大意 给定二维平面上 3 个整数表示的点 A,B,C,在三角形 ABC 内随机选一点 P,求期望$E ...

  3. 2019 牛客多校第一场 E ABBA

    题目链接:https://ac.nowcoder.com/acm/contest/881/E 题目大意 问有多少个由 (n + m) 个 'A' 和 (n + m) 个 'B',组成的字符串能被分割成 ...

  4. python字符串去重及排序 牛客_2018牛客多校第一场 D.Two Graphs

    题意: n个点,m1条边的图E1,n个点,m2条边的图E2.求图E2有多少子图跟图E1同构. 题解: 用STL的全排列函数next_permutation()枚举映射.对于每一种映射枚举每一条边判断合 ...

  5. 2020 牛客多校第一场

    2020 牛客多校第一场 A. B-Suffix Array 后缀数组的思想:倍增+桶排序的方式找出一串连续序列后缀的大小.虽说正常使用的时候都是字典序,但是只要修改排序方式,也能够达到一个类似的&q ...

  6. 2019牛客多校第九场AThe power of Fibonacci(广义BM)

    2019牛客多校第九场AThe power of Fibonacci(广义BM) 题目大意 求斐波那契数列m次方的前n项和 解题思路 显然,斐波那契的m次方前缀和依然是线性递推,因此考虑用exBM求解 ...

  7. Quadratic equation(二次剩余)2019牛客多校第九场

    链接:https://ac.nowcoder.com/acm/contest/889/B 来源:牛客网 题目描述 Amy asks Mr. B problem B. Please help Mr. B ...

  8. 【多校训练】2021牛客多校第一场

    [前言] 组队训练的第一场比赛,感觉这场出题十分阴间,后面几个乱搞题根本不会.jpg 赛时只过了5题,rk123,学校参加5/8. A. Alice and Bob [题意] 两人博弈,每次一个人从一 ...

  9. 2018牛客多校第一场 Monotonic Matrix (LGV引理)

    链接:https://www.nowcoder.com/acm/contest/139/A 来源:牛客网 题目描述 Count the number of n x m matrices A satis ...

  10. 2019年牛客多校第一场B题 Integration 定积分 裂项相消

    题目链接: https://ac.nowcoder.com/acm/contest/881/B 题解: 转发一个大佬的博客,裂项相消,很容易看懂. https://blog.csdn.net/dill ...

最新文章

  1. 无法在WEB服务器上启动调试,Web 服务器配置不正确
  2. 两位智源青年科学家榜上有名!2020青橙奖公布
  3. cm 怎么限制hue数据下载_0724-6.2.0-CM接管rpm方式安装的无CM的CDH集群-2
  4. iOS中 动态启动图GIF的简单设置 韩俊强的博客
  5. C语言:L1-031 到底是不是太胖了 (10分)(解题报告)
  6. C# ConcurrentBag的实现原理
  7. PHP常用字符串函数
  8. 迭代列表不要For循环,这是Python列表推导式最基本的概念
  9. VMware相关的缩略语和缩略语
  10. Stanford CS230深度学习(五)CNN和ResNet
  11. 查看oracle的版本、所在表空间、字符集及查询一个表的所有字段名和数据类型
  12. canvas节点无法导出图片_html页面、canvas导出图片
  13. WPS个人版安装VBA教程
  14. 阿里云盘的webdav协议开源实现
  15. 【风马一族_SQL Server】
  16. Tableau 中多张表的联接
  17. 用android怎么做一个机器人,怎样写一个类似ROS的易用的android机器人框架(2)
  18. PS-制作动态图GIF
  19. Matlab图像处理入门教程(菜鸟级)
  20. 根据excel模板导出excel

热门文章

  1. ecplise tomcat忽然出现404
  2. 如何解决Linux 系统下 ifconfig 命令无网络接口 ens33
  3. Xshell连接不上虚拟机,或许该这样做!
  4. xtrabackup与mysqldump对比测试
  5. mvc5 新手入门--ASP.NET MVC5中View-Controller间数据的传递
  6. Android Studio 将github作为远程maven仓库
  7. Name Mangling and extern “C” in C++
  8. 如何做一个让开发人员看得起的软件测试人员
  9. windows phone笔记
  10. IWAM账号 HTTP500内部错误