2017 杭电多校联赛第二场 1003 Maximum Sequence(单调队列)HDU 6047
Maximum Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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;
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;
题目大意:
b序列表示a[ b[i] ]可以用多少次
解题思路:
由样例举例
8 11 8 5
↓ 减去i
7 9 5 1
↓ 因为b数组
I = 1 2 3 4
7 9 5 1
可以使用的次数 1 1 1 1
↓ 因为7<9
I = 1 2 3 4
7 9 5 1
可以使用的次数 0 2 1 1
↓
I = 2 3 4 5
9 5 1 9-i
可以使用的次数 1 1 1 0
ans = ans + 9
↓ 因为9 - i = 4 >1
I = 2 3 4 5
9 5 1 4
可以使用的次数 1 1 0 1
由此下去 ans = 9 + 9 + 5 + 4
AC代码
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int a[500004],b[500004];
int n;
long long modx=1e9+7;
int main()
{while(~scanf("%d",&n)){//memset(a,0,sizeof(a));//memset(b,0,sizeof(b));int k;for(int i=1;i<=n;i++){a[i]=0;b[i]=0;scanf("%d",&a[i]);a[i]=a[i]-i;} for(int i=1;i<=n;i++){scanf("%d",&k);b[k]++; }int yu=a[n],yi=n;for(int i=n-1;i>=1;i--){if(a[i]<yu){ b[yi]+=b[i];b[i]=0;}else{yu=a[i];yi=i;}}// for(int i=1;i<=n;i++)//{// printf("%d %d\n",a[i],b[i]);//}int l=n;long long sum=0;int i=1;while(1){if(l==n+n)break;if(b[i]>0){l++;a[l]=a[i]-l;b[l]=1;b[i]--;yu=a[l];yi=l;for(int j=l-1;j>=1;j--){if(a[j]<yu){b[yi]+=b[j];b[j]=0;}elsebreak;}sum=(sum+a[i]+modx)%modx;//printf("%dbvisedhf\n",a[i]);sum%=modx;//printf("%lld\n",sum);}elsei++;}printf("%lld\n",sum);}return 0;
}
2017 杭电多校联赛第二场 1003 Maximum Sequence(单调队列)HDU 6047相关推荐
- 莫队 ---- 值域分块处理优化字典树上的查询 杭电多校2021第二场1004 i love counting
题目链接 题目大意: 就是给你nnn个数,mmm次询问 每次询问给你l,r,a,bl,r,a,bl,r,a,b问你在[l,r][l,r][l,r]区间里面有多少种种种数c(XOR)a≤bc(XOR)a ...
- HDU 5734 Acperience (公式推导) 2016杭电多校联合第二场
题目:传送门. #include <iostream> #include <algorithm> #include <cstdio> #include <cs ...
- 杭电多校联赛2017年总结
杭电多校联赛2017年总结 时间确实过得挺快,一个月很快结束,说实在的,一个月了,每次比赛都是混两道签到题,然后就开始挂机了,确实很不甘心,看着联赛的排名,确实感觉,和强校之前的差距还是很大的,P ...
- 杭电多校第六场个人补题6 7 9 10 12
杭电多校第六场个人补题6 7 9 10 12 6 题意 给定一棵有n结点的树,点权为1~n,求对所有结点子树的mex操作和的最大值 思路 其实就是从最底部开始网上找,由于0是唯一的一个,所欲最好给在最 ...
- 2022杭电多校第八场题解
2022杭电多校第八场 Theramore(思维) 题意 给定一个01字符串,每次可以将一个奇数长度的区间翻转,求操作后字典序最小的字符串. 分析 翻转奇数长度的区间,元素位置的奇偶性不变,统计奇数位 ...
- 杭电多校第七场 1011 Kejin Player HDU(6656)
杭电多校第七场 1011 Kejin Player 题意:给你N行,代表从i级有花费a[i]元的r[i]/s[i]的概率达到i+1级,剩下的概率中可能会到达x[i]级.然后询问从L级到R级的花费会是多 ...
- 2019杭电多校 第七场 Kejin Player 6656(求期望值)
2019杭电多校 第七场 Kejin Player 6656(求期望值) 题目 http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意 给你n,q.表示有n ...
- 2019杭电多校第9场1002 Rikka with Cake HDU6681
2019杭电多校第9场1002 Rikka with Cake HDU6681 题意:给你若干个点按上下左右切割平面,最后问平面内有几块被切割开来. 解法1:红黑树+思维+贪心 A:根据欧拉定理可以得 ...
- 2019.7.29 杭电多校第三场小结
index > 杭电多校第三场 题号 标题 AC 做法 状态 6603 Azshara's deep sea (51/150)34.00% 6604 Blow up the city (213/ ...
最新文章
- 【青少年编程(第24周)】Python-Turtle组队学习结营!
- 看看那些令你惊叹的PCB设计艺术
- 时间序列python复杂网络实例_基于时间序列数据的复杂网络重构
- gh0st源码分析与远控的编写(三)
- SAP Digital Asset Management by OpenText for CRM
- Oracle入门(十四.17)之procedure传递参数
- IE8无法调试?IE进入不了调试状态
- Android代码设置角标,Android上的Badge,快速实现给应用添加角标
- yum httpd安装详解
- java 生成jar包并保留注释
- 《新概念模拟电路》系列电子书下载
- Visual Studio 2022配置GAMP出现 LNK2019无法解析外部符号_imp_timeGetTime@0
- 【炫丽跑车win7主题】
- GitHub 上有哪些考研神器?
- 无线控制需要服务器,无线局域网无线控制器管理用户通过RADIUS服务器认证的配置-Cisco.PDF...
- uni-app修改代码,微信开发者工具不更新
- UltraISO下载安装方式
- 生物多样性 分类器多样性_优先考虑多样性是谁的工作
- 坐标系之间的主要转换
- 招*行赢积分【题库】