Maximum Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1152    Accepted Submission(s): 537

Problem Description
Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: Given the sequence 11, 23, 30, 35, what is the next number? Steph always finds them too easy for such a genius like himself until one day Klay comes up with a problem and ask him about it.

Given two integer sequences {ai} and {bi} with the same length n, you are to find the next n numbers of {ai}: an+1…a2n. Just like always, there are some restrictions on an+1…a2n: for each number ai, you must choose a number bk from {bi}, and it must satisfy ai≤max{aj-j│bk≤j<i}, and any bk can’t be chosen more than once. Apparently, there are a great many possibilities, so you are required to find max{∑2nn+1ai} modulo 109+7 .

Now Steph finds it too hard to solve the problem, please help him.

 
Input
The input contains no more than 20 test cases.
For each test case, the first line consists of one integer n. The next line consists of n integers representing {ai}. And the third line consists of n integers representing {bi}.
1≤n≤250000, n≤a_i≤1500000, 1≤b_i≤n.
 
Output
For each test case, print the answer on one line: max{∑2nn+1ai} modulo 109+7。
 
Sample Input
4
8 11 8 5
3 1 4 2
 
Sample Output
27

Hint

For the first sample:
1. Choose 2 from {bi}, then a_2…a_4 are available for a_5, and you can let a_5=a_2-2=9;
2. Choose 1 from {bi}, then a_1…a_5 are available for a_6, and you can let a_6=a_2-2=9;

 
Source

/*
* @Author: Lyucheng
* @Date: 2017-07-28 15:53:31
* @Last Modified by: Lyucheng
* @Last Modified time: 2017-07-28 17:38:20
*/
/*
题意:给你序列a,b,长度为n,让你构造a序列n+1~n*2的元素,有一个规则:
ai≤max{aj-j│bk≤j<i} 思路:线段树维护a的最大值
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> #define MAXN 250009
#define lson i*2,l,m
#define rson i*2+1,m+1,r
#define INF 0x3f3f3f3f
#define LL long long
const LL MOD = 1e9+; using namespace std; int n;
int a[MAXN];
int b[MAXN];
int sum[MAXN*]; void pushup(int i,int l,int r){
sum[i]=max(sum[i*],sum[i*+]);
} void build(int i,int l,int r){
if(l==r){
if(l<=n)
sum[i]=a[l]-l;
return;
}
int m=(l+r)/;
build(lson);
build(rson);
pushup(i,l,r);
} void update(int key,int val,int i,int l,int r){
if(l==r){
sum[i]=val;
return ;
}
int m=(l+r)/;
if(m>=key) update(key,val,lson);
else update(key,val,rson);
pushup(i,l,r);
} int query(int ql,int qr,int i,int l,int r){
if(ql<=l&&r<=qr){
return sum[i];
}
int m=(l+r)/;
int res=-;
if(m>=ql) res=max(res,query(ql,qr,lson));
if(m<qr) res=max(res,query(ql,qr,rson));
return res;
} int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(scanf("%d",&n)!=EOF){
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=;i<=n;i++){
scanf("%d",&b[i]);
}
build(,,n*);
sort(b+,b+n+);
LL res=;
for(int i=n+;i<=*n;i++){
int l=b[i-n];//b中剩余最小的
int cur=query(l,i-,,,n*);//a中最大的
update(i,cur-i,,,n*);
res+=cur;
res%=MOD;
}
printf("%lld\n",res);
}
return ;
}

HDU 6047 Maximum Sequence的更多相关文章

  1. HDU 6047 - Maximum Sequence | 2017 Multi-University Training Contest 2

    /* HDU 6047 - Maximum Sequence [ 单调队列 ] 题意: 起初给出n个元素的数列 A[N], B[N] 对于 A[]的第N+K个元素,从B[N]中找出一个元素B[i],在 ...

  2. HDU 6047 Maximum Sequence(线段树)

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

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

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

  4. 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) ...

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

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

  6. hdu 6047 Maximum Sequence(贪心)

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

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

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

  8. hdu 6047 Maximum Sequence 贪心

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

  9. HDU 6047 Maximum Sequence (贪心+单调队列)

    题意:给定一个序列,让你构造出一个序列,满足条件,且最大.条件是 选取一个ai <= max{a[b[j], j]-j} 析:贪心,贪心策略就是先尽量产生大的,所以就是对于B序列尽量从头开始,由 ...

随机推荐

  1. Chrome控制台选择器简介

    Chrome的控制台是支持用$来获取元素的,这点可能是很多人不知道的.本篇文章将会简单介绍怎样更好的来使用这种快捷方式来获取元素. 判断当前窗口的$是来自谁的 我们知道jQ里面经常使用$来进行元素选择 ...

  2. 开始使用ASP.NET Core - 创建第一个Web应用

    .NET Core 是.NET Framework的新一代跨平台应用程序开发框架,是微软在一开始发展时就开源的软件平台,由于 .NET Core 的开发目标是跨平台的 .NET 平台,因此 .NET ...

  3. AngularJS -- Module (模块)

    点击查看AngularJS系列目录 转载请注明出处:http://www.cnblogs.com/leosx/ 什么是AngularJS的模块 我们所说的模块,是你的AngularJS应用程序的一个组 ...

  4. Split分割字符串

    第一种方法:打开vs.net新建一个控制台项目.然后在Main()方法下输入下面的程序. string s="abcdeabcdeabcde"; string[] sArray=s ...

  5. .h(头文件) .lib(库文件) .dll(动态链接库文件) 之间的关系和作用的区分

    .h头文件是编译时必须的,lib是链接时需要的,dll是运行时需要的.附加依赖项的是.lib不是.dll,若生成了DLL,则肯定也生成 LIB文件.如果要完成源代码的编译和链接,有头文件和lib就够了 ...

  6. 【转】Spark运行过程

    http://www.cnblogs.com/1130136248wlxk/articles/6289717.html

  7. 如何使用git 发布源码到CodePlex

    github 是分布式源码管理系统 codeplex 是微软的开源社区 将git中源码分享到codeplex社区其实很方便,按照如下步骤: 1:注册codeplex 帐号或使用微软的已有的帐号 2:下 ...

  8. IIS7中JS、CSS、Image无法显示和加载解决方案

    前两天把机器从Windows7升级到Windows10,IIS也跟着升级了,在获取项目搭载IIS上发现原有的页面中所有的JS.CSS.Image都无法访问,提示500错误,起初以为是IIS没有装好 重 ...

  9. [js高手之路]封装运动框架实战左右与上下滑动的焦点轮播图

    在这篇文章[js高手之路]打造通用的匀速运动框架中,封装了一个匀速运动框架,我们在这个框架的基础之上,加上缓冲运动效果,然后用运动框架来做幻灯片(上下,左右),效果如下: 1 2 3 4 5 // 0 ...

  10. CoreData归纳使用

    1.CoreData简介 2.CoreData数据模型 3.CoreData的主要对象 4.使用CoreData实现数据存储 一.CoreData简介 CoreData用做数据持久化,是数据持久化的最 ...