HDU 6047 Maximum Sequence
Maximum Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1152 Accepted Submission(s): 537
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.
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.
8 11 8 5
3 1 4 2
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;
/*
* @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的更多相关文章
- 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],在 ...
- HDU 6047 Maximum Sequence(线段树)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...
- HDU 6047 Maximum Sequence(贪心+线段树)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...
- 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) ...
- 【多校训练2】HDU 6047 Maximum Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=6047 [题意] 给定两个长度为n的序列a和b,现在要通过一定的规则找到可行的a_n+1.....a_2n,求su ...
- hdu 6047 Maximum Sequence(贪心)
Description Steph is extremely obsessed with "sequence problems" that are usually seen on ...
- 2017ACM暑期多校联合训练 - Team 2 1003 HDU 6047 Maximum Sequence (线段树)
题目链接 Problem Description Steph is extremely obsessed with "sequence problems" that are usu ...
- hdu 6047 Maximum Sequence 贪心
Description Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: ...
- HDU 6047 Maximum Sequence (贪心+单调队列)
题意:给定一个序列,让你构造出一个序列,满足条件,且最大.条件是 选取一个ai <= max{a[b[j], j]-j} 析:贪心,贪心策略就是先尽量产生大的,所以就是对于B序列尽量从头开始,由 ...
随机推荐
- nmcli命令大集合
nmcli命令 地址配置工具:nmcli nmcli device 查看所有网卡的信息 nmcli device status 和numcli device 相同 nmcli device ...
- [js高手之路] 设计模式系列课程 - DOM迭代器(2)
如果你对jquery比较熟悉的话,应该用过 eq, first, last, get, prev, next, siblings等过滤器和方法.本文,我们就用迭代设计模式来封装实现,类似的功能 < ...
- 压缩感知中的lp球:p范数最优化为什么总会导致一个稀疏的解的原因
转自:彬彬有礼. 压缩感知中的lp球:p范数最优化为什么总会导致一个稀疏的解的原因 http://blog.csdn.net/jbb0523/article/details/40268943 题目: ...
- SAP Gateway简介
SAP Gateway在S4/HANA时代的ABAP开发模型中有着重要的地位.SAP Gateway是什么?它对ABAP开发有怎样的影响?可以为我们提供哪些方便?这篇译文将浅要地讨论这些话题. SAP ...
- Spring3.2不支持jdk8
解决方案: http://stackoverflow.com/questions/24128045/spring-context-initialization-failed-with-java-lan ...
- Android开发之基于监听的事件处理
在Android 应用开发过程中,常用监听事件如下:(1) ListView事件监听setOn ItemSelectedListener:鼠标滚动时触发setOnItemClickListener: ...
- Problem 2144 Shooting Game fzu
Problem 2144 Shooting Game Accept: 99 Submit: 465Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- hdu3018欧拉回路题
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- webservice部署到服务器报错
System.Net.WebException: 基础连接已经关闭: 发送时发生错误. ---> System.IO.IOException: 从传输流收到意外的 EOF 或 0 个字节. 在 ...
- C#之基础
引子:C#是.NET平台所支持的多种语言中的一门编程语言,它是一门面向对象编程语言.面向对象语言的三大基本特性是:封装.继承.多态.学过C#的人肯定都知道,C#和Java极其相似.我已经学过C语言,现 ...