2017 多校赛 第二场

Posted liylho

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017 多校赛 第二场相关的知识,希望对你有一定的参考价值。

1003.Maximum Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


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+1a2n. Just like always, there are some restrictions on an+1a2n: 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
 
思路:贪心,用一个数组记下从i到n的a[i]-i的最大值pre[i],可以得到pre[i]=max(pre[i+1],a[i]-i),然后容易得到b[k]从小往大取时,后n项之和最大,所以a[n+1]=pre[b[1]](后n项会呈单调不递增趋势,a[n+1]-n-1即为之后取最大值的比较对象)。
代码:
 1 #include "cstdio"
 2 #include "stdlib.h"
 3 #include "iostream"
 4 #include "algorithm"
 5 #include "string"
 6 #include "cstring"
 7 #include "queue"
 8 #include "cmath"
 9 #include "vector"
10 #include "map"
11 #include "set"
12 #define db double
13 #define ll long long
14 #define inf 0x3f3f3f
15 using namespace std;
16 const int N=3e5+5;
17 const int mod=1e9+7;
18 #define rep(i,x,y) for(int i=x;i<=y;i++)
19 //char s[N],t[N];
20 db  pi=3.14;
21 //int s[N],w[N];
22 int a[N],b[N];
23 int pre[N];
24 int main()
25 {
26     int n;
27     while(scanf("%d",&n)==1){
28         for(int i=1;i<=n;i++){
29             scanf("%d",a+i);
30             a[i]-=i;
31         }
32         memset(pre,0, sizeof(pre));
33         for(int i=n;i>=1;i--) pre[i]=max(a[i],pre[i+1]);
34         for(int i=1;i<=n;i++) scanf("%d",&b[i]);
35         sort(b+1,b+n+1);
36         int ma=0;
37         ll ans=pre[b[1]];
38         for(int i=2;i<=n;i++){
39             ma=max(pre[b[1]]-n-1,pre[b[i]]);
40             ans=(ma+ans)%mod;
41 //            printf("%d\n",ma);
42         }
43         printf("%lld\n",ans);
44     }
45 
46 }

 

 

以上是关于2017 多校赛 第二场的主要内容,如果未能解决你的问题,请参考以下文章

hdu_6050: Funny Function (2017 多校第二场 1006) 找规律

hdu_6047: Maximum Sequence (2017 多校第二场 1003)贪心

hdu_6055 : Regular polygon (2017 多校第二场 1011) 计算几何

补题多校联合训练第二场

HDU 5305 Friends (搜索+剪枝) 2015多校联合第二场

2019 杭电多校 第二场