题目链接  2017 ACM-ICPC World Finals Problem D

(这题细节真的很多)

把所有的(pi,di)按横坐标升序排序。

对于某个点,若存在一个点在他左下角,那么这个点就是可以去掉的。

因为这个点的答案无论怎么优都劣于他左下角的这个点的答案。

对所有的(qj, ej)也同理。

然后就是一个分治的过程。

solve(L, R, l, r)表示对所有的在[L, R]中的买入点x都要找到一个最适合x的点y并更新答案。

首先对于某个买入点mid,在所有卖出点中找到横纵坐标都大于他的点的集合(是一段连续的点)

设这段点的下标范围为[ql, qr]

然后在这一段连续的点中找到最优的决策点Mid。

那么接下来递归下去就是solve(L, mid - 1, l, Mid)和solve(mid + 1, R, Mid, r)。

注意边界条件的特判。(也就是当横纵坐标都大于当前点的集合为空集时)

#include <bits/stdc++.h>

using namespace std;

#define	rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) typedef long long LL; const int N = 5e5 + 10; struct node{
LL x, y;
friend bool operator < (const node &a, const node &b){
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
} a[N], b[N], wb[N]; LL x[N];
LL ans;
int n, m, px, py; void solve(int l, int r, int st, int ed){
if (l > r) return;
int mid = (l + r) >> 1;
LL mx = 0, vy = a[mid].y;
int pos = 0;
for (int i = upper_bound(x + st, x + ed + 1, a[mid].x) - x; i <= ed && vy < b[i].y; ++i){
LL val = (b[i].x - a[mid].x) * (b[i].y - a[mid].y);
if (val > mx) mx = val, pos = i;
} ans = max(ans, mx);
if (!pos){
if (a[mid].y < b[st].y) solve(l, mid - 1, st, ed);
if (a[mid].x < b[ed].x) solve(mid + 1, r, st, ed);
} else{
solve(l, mid - 1, st, pos);
solve(mid + 1, r, pos, ed);
}
} int main(){ scanf("%d%d", &n, &m);
rep(i, 1, n) scanf("%lld%lld", &a[i].x, &a[i].y);
rep(i, 1, m) scanf("%lld%lld", &wb[i].x, &wb[i].y);
sort(a + 1, a + n + 1);
sort(wb + 1, wb + m + 1); px = py = 1, b[1] = wb[m]; rep(i, 2, n) if (a[i].y < a[px].y) a[++px] = a[i];
dec(i, m - 1, 1) if (wb[i].y > b[py].y) b[++py] = wb[i];
reverse(b + 1, b + py + 1);
rep(i, 1, py) x[i] = b[i].x; ans = 0;
solve(1, px, 1, py);
printf("%lld\n", ans);
return 0;
}

  

Codeforces Gym 101471D Money for Nothing(2017 ACM-ICPC World Finals D题,决策单调性)的更多相关文章

  1. 2017 ACM/ICPC 新疆赛区 I 题 A Possible Tree 带权并查集

    传送门 题意:给定一棵带权树的形态, 但是并不知道每天条边的具体权重. 然后给m个信息, 信息格式为u v val, 表示在树上u 到 v 的路径上经过的边的权重的异或和为val, 问前面最多有多少个 ...

  2. 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  3. 2017 ACM ICPC Asia Regional - Daejeon

    2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...

  4. 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest

    2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...

  5. 2017 ACM/ICPC Shenyang Online SPFA+无向图最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  6. 2017 ACM/ICPC Asia Regional Qingdao Online

    Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submi ...

  7. ACM - ICPC World Finals 2013 C Surely You Congest

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 试题来源 ACM/ICPC World Fin ...

  8. HDU - 6215 2017 ACM/ICPC Asia Regional Qingdao Online J - Brute Force Sorting

    Brute Force Sorting Time Limit: 1 Sec  Memory Limit: 128 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  9. 2017 ACM/ICPC Asia Regional Shenyang Online(部分题解)

    HDU 6197 array array array 题意 输入n和k,表示输入n个整数和可以擦除的次数k,如果至多擦除k次能是的数组中的序列是不上升或者是不下降序列,就是魔力数组,否则不是. 解题思 ...

随机推荐

  1. String使用方法详解

    标准c++中string类函数介绍 注意不是CString 之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够.字符串长度等等,而且作 ...

  2. (转) Redis哨兵的详解

    1 哨兵的作用 哨兵是redis集群架构中非常重要的一个组件,主要功能如下: 1. 集群监控:负责监控redis master和slave进程是否正常工作 2. 消息通知:如果某个redis实例有故障 ...

  3. 菜鸟学Linux - bash的配置文件

    bash是各大Linux发行版都支持的shell.当我们登陆bash的时候,虽然我们什么都没做,但是我们已经可以在bash中调用各种各样的环境变量了.这是因为,系统中已经定义了一系列的配置文件,以及加 ...

  4. 赢友网络通用框架V10.0.0(WinuAppSoft) 基础框架设计表

    /* * 版权所有:赢友网络(http://www.winu.net/) * 开发人员:新生帝(JsonLei) * 设计名称:赢友网络通用框架V10.0.0(WinuAppSoft) * 设计时间: ...

  5. Careercup - Microsoft面试题 - 23123665

    2014-05-12 07:44 题目链接 原题: Given an array having unique integers, each lying within the range <x&l ...

  6. 【Remove Duplicates from Sorted Array II】cpp

    题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...

  7. leetcode 【 Pascal's Triangle 】python 实现

    题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,R ...

  8. pip更新产生的问题及其解决方法?

    运行 pip3 install --upgrade pip 发生错误: from pip import main ImportError: cannot import name 'main' 将以下代 ...

  9. MyEclipse断点调试方法

    MyEclipse断点调试方法 最基本的操作是: 1, 首先在一个java文件中设断点,然后运行,当程序走到断点处就会转到debug视图下, 2, F5键与F6键均为单步调试,F5是step into ...

  10. HDU 4178 模拟

    Roll-call in Woop Woop High Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...