/*
HDU 6047 - Maximum Sequence [ 单调队列 ]
题意:
起初给出n个元素的数列 A[N], B[N]
对于 A[]的第N+K个元素,从B[N]中找出一个元素B[i],在 A[] 中找到一个数字A[p]满足 B[i] <= p <= N+K-1
令 A[N+K] = A[p]-p,直到A[]的长度等于2N
问 A[N+1] + A[N+2] + ... + A[N<<1] 最大是多少
分析:
将A[]中元素全部减去其下标
将B[]排序,可分析一定是从小往大选择最优
每次从可以选择的A[]中选最大的一个,过程用单调队列来实现
编码时长:13分钟
*/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL MOD = 1e9+7;
const int N = 250004;
int n;
int a[N<<1], b[N];
struct Node {
int x, id;
}q[N<<1];
int head, tail;
void solve()
{
for (int i = 1; i <= n; i++) a[i] -= i;
head = tail = 0;
for (int i = 1; i <= n; i++)
{
while (head < tail && q[tail-1].x < a[i]) tail--;
q[tail++] = Node{a[i], i};
}
for (int i = n+1; i <= n<<1; i++)
{
while (head < tail && q[head].id < b[i-n]) head++;
a[i] = q[head].x-i;
while (head < tail && q[tail-1].x < a[i]) tail--;
q[tail++] = Node{a[i], i};
}
}
int main()
{
while (~scanf("%d", &n))
{
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
sort(b+1, b+1+n);
solve();
LL ans = 0;
for (int i = n+1; i <= n<<1; i++)
{
ans += a[i] + i;
if (ans > MOD) ans -= MOD;
if (ans < 0) ans += MOD;
}
ans = (ans%MOD + MOD) % MOD;
printf("%lld\n", ans);
}
}

  

HDU 6047 - Maximum Sequence | 2017 Multi-University Training Contest 2的更多相关文章

  1. hdu 6047: Maximum Sequence (2017 多校第二场 1003)【贪心】

    题目链接 可以贪心写,先把b数组按从小到大的顺序排个序,根据b[i]的值来产生a[n+i] 借助一个c数组,c[i]记录,j从i到n,a[j]-j的最大值,再加上一个实时更新的变量ma,记录从n+1到 ...

  2. 2017 Multi-University Training Contest - Team 2&&hdu 6047 Maximum Sequence

    Maximum Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDU 6047 Maximum Sequence(线段树)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...

  4. HDU 6047 Maximum Sequence

    Maximum Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU 6047 Maximum Sequence(贪心+线段树)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...

  6. 【多校训练2】HDU 6047 Maximum Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=6047 [题意] 给定两个长度为n的序列a和b,现在要通过一定的规则找到可行的a_n+1.....a_2n,求su ...

  7. hdu 6047 Maximum Sequence(贪心)

    Description Steph is extremely obsessed with "sequence problems" that are usually seen on ...

  8. 2017ACM暑期多校联合训练 - Team 2 1003 HDU 6047 Maximum Sequence (线段树)

    题目链接 Problem Description Steph is extremely obsessed with "sequence problems" that are usu ...

  9. hdu 6047 Maximum Sequence 贪心

    Description Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: ...

随机推荐

  1. SQL Server 2019 Linux Docker 在主机上以其他非根用户的身份运行容器

    docker logs mssql2019SQL Server 2019 will run as non-root by default.This container is running as us ...

  2. php 取post数据的三种方式

    $_POST.$GLOBALS['HTTP_RAW_POST_DATA'].file_get_contents("php://input") 都有用来取post数据,用下来感觉大致 ...

  3. php学习历程1——注册、登录(面向过程、面向对象)

    首先放一张天空之城 Php入门来的第一个小项目,首先做的是一个简陋的文章管理系统.有登录.注册.文章list.添加文章.修改文章.删除文章.分页这几个小功能. 面向过程的编码 面向对象的编码 首先做的 ...

  4. spark教程(19)-sparkSQL 性能优化之谓词下推

    在 sql 语言中,where 表示的是过滤,这部分语句被 sql 层解析后,在数据库内部以谓词的形式出现: 在 sparkSQL 中,如果出现 where,它会现在数据库层面进行过滤,一般数据库会有 ...

  5. css多种方式实现等宽布局

    本文讲的等宽布局是在不手动设置元素宽度的情况下,使用纯css实现各个元素宽度都相当的效果. 1.使用table-cell实现(兼容ie8) <style> body,div{ margin ...

  6. 牛客 132C 简单瞎搞题 (bitset)

    大意: 给定序列$a$的第$i$个元素的取值范围$[L_i,R_i]$, 求$a$的平方和的种类数. 用bitset优化, 复杂度$O(\frac{n^5}{\omega})$ #include &l ...

  7. 推荐系统遇上深度学习(十)--GBDT+LR融合方案实战

    推荐系统遇上深度学习(十)--GBDT+LR融合方案实战 0.8012018.05.19 16:17:18字数 2068阅读 22568 推荐系统遇上深度学习系列:推荐系统遇上深度学习(一)--FM模 ...

  8. MySQL 存储引擎的类型以及选择

    针对MySQL,数据最终以什么样的形式保存?以及数据保存在硬盘的什么位置? 1.MySQL的存储引擎 MySQL属于数据管理系统(DBMS),其中包括数据库,负责存储数据:还有数据库访问管理的接口系统 ...

  9. No compiler is provided in this environment. Perhaps you are running on a JR

    maven编译项目时出错,提示信息如下: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3 ...

  10. docker基础知识

    兴起于2010年,2013年docker开源. 什么是docker? built ship run 官方定位: Docker is a world's leading software contain ...