bnu 12872 Array Diversity

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.

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.

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.

Constraints:

T <= 50
N <= 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

Sample Output

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;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值