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序列尽量从头开始,由 ...
随机推荐
- Unity 3D 之贪吃蛇 Text 心得 & Audio
当我们需要在游戏街面上增加文本时, 我们就需要用到Text 组件 注意: 当文本的长度或者宽度不够时,字体将无法显示. 因为是面对组件编程,所以每一个组件的component都可以同过GetCompo ...
- idea导出war包
使用idea一个月了还没有用到导出war,今天突然需要我来部署测试war包,想使用myeclipse的,转念一想太掉价了 废话少说,直接上菜 如果你没有第一步操作我建议你配置一下你的idea 当然还有 ...
- angular学习笔记04 理论加实践
scope: 布尔型或对象(默认为false) ,为true时继承父作用域并创建一个新的作用域隔离作用域具有隔离作用域的指令最主要的使用场景是创建可复用的组件, 组件可以在未知上下文中使用,并且可以避 ...
- ClassLoader类加载机制&&JVM内存管理
一.ClassLoader类加载机制 在java中类加载是遵循委派双亲加载的:通过调用loadClass方法逐级往上传递委派加载请求,当找不到父ClassLoader时调用其findClass方法尝试 ...
- Linux之不得不说的init(Linux启动级别的含义 init 0-6)
init 0:关机: init 1:单用户模式(只root进行维护): init 2:多用户 init 3:完全多用户 init 4:安全模式 init 5:图形化 init 6:重启 可以在/etc ...
- 超级密码 hdu1226 bfs
超级密码 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- Problem 2062 Suneast & Yayamao 二进制(多重背包的理解基础)
Problem 2062 Suneast & Yayamao Accept: 143 Submit: 313T ...
- C#下的两种加密方式MD5和DEC
md5加密 /// <summary> /// MD5加密 /// </summary> /// <param name="toCryStri ...
- 【Windows 10 应用开发】细说文本资源文件(resw)
最近,小戏骨版<红楼梦>很是火热,老周一口气看完了9集,一直看到 Surface 的风扇呼呼响.林黛玉和薛宝钗这两个角色都演得不怎么样,倒是演史湘云的娃娃演得不错,老周甚是喜欢. 于是,昨 ...
- css3弹性盒模型flex快速入门与上手1
一.什么是flex? flex是css3中引入的一种布局方式,可以非常灵活高效控制元素的排列与对齐方式,大多人称之为弹性布局. 二.怎么使用flex? 任何一个容器都可以指定为flex布局 #box ...