HDU 6047 17多校 Maximum Sequence(优先队列)
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.
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;
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
using namespace std; #define MOD 1000000000+7 struct node
{
long long num,ip,dis;
}; long long b[]; struct cmp
{
bool operator()(node q,node p)
{
return q.dis<p.dis;
}
}; int main()
{
long long n;
while(~scanf("%lld",&n))
{
priority_queue<node,vector<node>,cmp>Q;
node a;
for(int i=;i<=n;i++)
{
scanf("%lld",&a.num);
a.ip=i;
a.dis=a.num-a.ip;
Q.push(a);
}
for(int i=;i<=n;i++)
scanf("%lld",&b[i]);
sort(b+,b++n);
long long res=;
for(int i=;i<=n;i++)
{
while(Q.top().ip<b[i])
Q.pop();
node tmp=Q.top();
res+=tmp.dis;
res%=MOD;
tmp.ip=n+i;
tmp.num=tmp.dis;
tmp.dis-=tmp.ip;
Q.push(tmp);
}
printf("%lld\n",res);
}
return ;
}
HDU 6047 17多校 Maximum Sequence(优先队列)的更多相关文章
- HDU 6140 17多校8 Hybrid Crystals(思维题)
题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...
- HDU 6143 17多校8 Killer Names(组合数学)
题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...
- HDU 3130 17多校7 Kolakoski(思维简单)
Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This seq ...
- HDU 6103 17多校6 Kirinriki(双指针维护)
Problem Description We define the distance of two strings A and B with same length n isdisA,B=∑i=0n− ...
- HDU 6106 17多校6 Classes(容斥简单题)
Problem Description The school set up three elective courses, assuming that these courses are A, B, ...
- HDU 6049 17多校2 Sdjpx Is Happy(思维题difficult)
Problem Description Sdjpx is a powful man,he controls a big country.There are n soldiers numbered 1~ ...
- HDU 6045 17多校2 Is Derek lying?
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others) Memory ...
- HDU 6124 17多校7 Euler theorem(简单思维题)
Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...
- HDU 6038 17多校1 Function(找循环节/环)
Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1. D ...
随机推荐
- 纯css实现顶部进度条随滚动条滚动
<!DOCTYPE html> <head> <meta charset="utf-8"> <meta http-equiv=" ...
- upsource初探
在JetBrains 的官网上,看到codereview的工具 upsource ,https://www.jetbrains.com/upsource/ 官方的英文文档 来看下博客园上有博主简单的 ...
- C# 3.0 / C# 3.5 扩展方法
概述 扩展方法是一种特殊的静态方法,可以像扩展类型上的实例方法一样进行调用,能向现有类型“添加”方法,而无须创建新的派生类型.重新编译或以其他方式修改原始类型. 扩展方法的定义实现: public s ...
- noip2014无线网络发射器选址
题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的 129 条东西向街道和 129 条南北向街道所形成的网格状,并且 ...
- NOIP2016玩具谜题
题目描述 小南有一套可爱的玩具小人, 它们各有不同的职业. 有一天, 这些玩具小人把小南的眼镜藏了起来. 小南发现玩具小人们围成了一个圈,它们有的面朝圈内,有的面朝圈外.如下图: 这时singersi ...
- POJ 2352 数星星
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 53816 Accepted: 23159 Descripti ...
- java继承,final,super,Object类,toString,equals,
Java中的内部类:成员内部类静态内部类方法内部类匿名内部类 内部类的主要作用如下: 1. 内部类提供了更好的封装,可以把内部类隐藏在外部类之内,不允许同一个包中的其他类访问该类 2. 内部类的方法可 ...
- linux basic test
Linux 1◆ 提供连接 2◆ connection baidu.com 3◆ vm tools install Reboot
- bzoj5016
题解: 吧询问变成前缀形式 然后莫队 代码: #include<bits/stdc++.h> ; using namespace std; ]; ,L=,R=; ,Ans[N]; bool ...
- svn服务器搭建及使用(三)
接下来,试试用TortoiseSVN修改文件,添加文件,删除文件,以及如何解决冲突等. 添加文件 在检出的工作副本中添加一个Readme.txt文本文件,这时候这个文本文件会显示为没有版本控制的状态, ...