码迷,mamicode.com
首页 > 其他好文 > 详细

2017 多校赛 第二场

时间:2017-07-27 23:29:28      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:set   print   parent   对象   step   tor   sts   esc   seq   

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 多校赛 第二场

标签:set   print   parent   对象   step   tor   sts   esc   seq   

原文地址:http://www.cnblogs.com/mj-liylho/p/7247765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!