bnu 12872 Array Diversity
来源:互联网 发布:淘宝新店一天刷几单好 编辑:程序博客网 时间:2024/06/06 12:42
Enough with this Harry Potter, please! What are we, twelve-year olds? Let's get our teeth into some real pumpkin pasties -- oops, programming problems!
Here we go!
Let's define the diversity of a list of numbers to be the difference between the largest and smallest number in the list.
For example, the diversity of the list (1, -1, 2, 7) = 7 - (-1) = 8.
A substring of a list is considered a non-empty sequence of contiguous numbers from the list. For example, for the list (1,3,7), the substrings are (1), (3), (7), (1,3), (3,7), (1,3,7). A subsequence of a list is defined to be a non-empty sequence of numbers obtained by deleting some elements from the list. For example, for the list (1,3,7), the subsequences are (1), (3), (7), (1,3), (3,7), (1,7), (1,3,7).
Given a list of length N find the number of substrings and subsequences in this list with the maximum diversity. If a substring/subsequence having maximum diversity occurs multiple times in the list, each of its occurances adds towards the answer. And tell Harry Potter your answer.
Here we go!
Let's define the diversity of a list of numbers to be the difference between the largest and smallest number in the list.
For example, the diversity of the list (1, -1, 2, 7) = 7 - (-1) = 8.
A substring of a list is considered a non-empty sequence of contiguous numbers from the list. For example, for the list (1,3,7), the substrings are (1), (3), (7), (1,3), (3,7), (1,3,7). A subsequence of a list is defined to be a non-empty sequence of numbers obtained by deleting some elements from the list. For example, for the list (1,3,7), the subsequences are (1), (3), (7), (1,3), (3,7), (1,7), (1,3,7).
Given a list of length N find the number of substrings and subsequences in this list with the maximum diversity. If a substring/subsequence having maximum diversity occurs multiple times in the list, each of its occurances adds towards the answer. And tell Harry Potter your answer.
Input
The first line contains T, the number of test cases. Then follow T test case blocks.
Each blocks starts with the first line containing the number N.
The second line contains a list of numbers in this list.
Each blocks starts with the first line containing the number N.
The second line contains a list of numbers in this list.
Output
For each test case, output the number of substrings and the number of subsequences in this list with the maximum diversity.
Since the answers maybe very large, output them modulo 1000000007.
N <= 100,000
Each number in the list is between 1 and 100,000 inclusive.
Time Limit: 2 s
Memory Limit: 32 MB
Since the answers maybe very large, output them modulo 1000000007.
Constraints:
T <= 50N <= 100,000
Each number in the list is between 1 and 100,000 inclusive.
Time Limit: 2 s
Memory Limit: 32 MB
Sample Input
3
3
1 2 3
4
1 4 3 4
3
3 2 1
3
1 2 3
4
1 4 3 4
3
3 2 1
Sample Output
1 2
3 6
1 2
3 6
1 2
/*以是否完全相同来分*/ #include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int maxx=100005;long long a[maxx],s1[maxx],s2[maxx];const int mod=1000000007;long long powx(int x)//手写2的n次方 {long long k=1;for(int i=0;i<x;i++)k=(k*2)%mod;return k;}int main(){int T,n;scanf("%d",&T);while(T--){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%lld",&a[i]);}long long minx=a[0],maxn=a[0];for(int i=1;i<n;i++){if(a[i]<minx)minx=a[i];if(a[i]>maxn)maxn=a[i];}long long l1=0,l2=0;for(int i=0;i<n;i++){if(a[i]==minx)s1[l1++]=i;//最小值的个数 if(a[i]==maxn)s2[l2++]=i;//最大值的个数}long long ans1,ans2;if(l1==n&&l2==n)//字符完全相同的情况 {long long x=n;x=(x*(n+1)/2)%mod;ans1=x;ans2=powx(n)-1;if(ans2<0)ans2+=mod;}else//非完全相等的情况 {ans1=0;int i,j,k;for( i=j=k=0;i<n&&j<l1&&k<l2;i++){ans1=(ans1+n-max(s1[j],s2[k]))%mod;//求ans1的方法,很直接的办法,不能写成ans1+=,会爆掉 if(s1[j]==i)j++;if(s2[k]==i)k++;}//求ans2的方法 long long y=powx(n-l1-l2);long long tmp;tmp=powx(l1)-1;if(tmp<0)tmp+=mod;y=(y*tmp)%mod;tmp=powx(l2)-1;if(tmp<0)tmp+=mod;y=(y*tmp)%mod;ans2=y;}printf("%lld %lld\n",ans1,ans2);}return 0;}
- bnu 12872 Array Diversity
- UVALive 5990 Array Diversity
- BNU Eugeny and Array
- diversity
- BNU
- diversity score
- Codeforces 844 A Diversity
- codeforces 844A Diversity
- Codeforces 844A Diversity
- Codeforces 844A Diversity
- codeforces 844A Diversity
- The Other Side of Diversity
- Ekelund's Diversity Icebreaker scale
- BNU 1042
- BNU 12883
- BNU 16225
- bnu 4067
- BNU 1065
- Linux 下 mysql 找不到 mysql.sock 文件的解决办法
- 联发科与晨星合并诞生新寨主
- IOS应用开发架构
- U-Boot直接引导zImage内核
- 装箱和拆箱数据类型转换
- bnu 12872 Array Diversity
- 一步步优化JVM五:优化延迟或者响应时间(2)
- 函数模板
- 时区日期处理及定时 (NSDate,NSCalendar,NSTimer,NSTimeZone) -- IOS(实例)
- Linux系统信息查看命令汇总
- 谷歌三大核心技术(二)Google MapReduce
- LTIB 详解(一) 安装与卸载
- LTIB 详解(二)配置选项与命令
- LTIB详解(三)包和源码