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. 双击打开Jar文件

    最近发现个诡异的问题,java环境变量明明配好了.但是双击xx.jar文件,就是不能直接打开运行. 先想到了第一个解决办法: 运行cmd.exe,cd到jar目录,执行 javaw -jar xxx. ...

  2. GCD之Apply

    dispatch_apply函数是dispatch_sync函数和dispatch_group的结合体.该函数将按指定的次数将指定的block追加到指定的dispatch queue中,并等待全部处理 ...

  3. xgboost安装指南(win10,win7 64位)

    ---恢复内容开始--- Win7 64位系统下安装XGBoost 1. 环境介绍 计算机系统:win7 64位 Xgboost版本:xgboost0.6 2. 依赖软件环境 1) python 64 ...

  4. Angularjs –– Expressions(表达式)

    点击查看AngularJS系列目录 转载请注明出处:http://www.cnblogs.com/leosx/ Angular的表达式 Angular的表达式和JavaScript代码很像,不过通常A ...

  5. Python uwsgi 无法安装以及编译报错的处理方式

    之前安装uwsgi的时候编译一步有出错,因为比较早,部分错误代码已经找不到了,网上找了部分错误信息, 现把解决方式共享出来. 环境:CentOS release 6.4   Python 2.7.3 ...

  6. NOIP2017SummerTraining0726

    三道比较简单的题,还以为是八校考试的题目,但是并不是,无语了,第三题其实看了挺久的,一看到图,就想到了二分图,网络流之类的算法,但是尽力往这个方向想了好久都没什么思路, 最后从简单入手,然而没什么结果 ...

  7. OpenVPN client端配置文件详细说明(转)

    本文将介绍如何配置OpenVPN客户端的配置文件.在Windows系统中,该配置文件一般叫做client.ovpn:在Linux/BSD系统中,该配置文件一般叫做client.conf.虽然配置文件名 ...

  8. windown快速安装xgboost

    记录xgboost的快速安装方式,该方式适合pyhton3.5/3.6版本. 系统: win10 64bit python版本:3.6 1. 下载xgboost编译好的whl包 下载路径为:http: ...

  9. 【笔记】如何查看HTTP请求头&&【实验吧】天下武功唯快不破

    打开Chrome浏览器,点击右上角“三”按钮. 点击工具-----再点击开发者工具   找到Network选项框.以百度经验页面为例,点击任务选框来查看网络请求流   在Network框内会有所有的请 ...

  10. java web 学习总结之 Servlet/JSP 编码问题

    Servlet和JSP编码问题 字节流: 1.得到OutputStream  字节流 OutputStream os = response.getOutputStream();   用默认编码输出数据 ...