Time Limit: 404MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu

Submit Status

Description

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 (STDIN):
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 (STDOUT):
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 <= 10
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
12

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 occurences adds towards the answer.   And tell Harry Potter your answer

Input (STDIN):

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 (STDOUT):

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 <= 10

N <= 100,000

Each number in the list is between 1 and 100,000 inclusive.

Sample Input:

3

3

1 2 3

4

1 4 3 4

3

3 2 1

Sample Output:

1 2

3 6

1 2

/**
题意 :给你一个串,问使得串中的最大值 - 最小值 为 deliver
然后看有多少个substring 和 subsequence 串 是的 deliver 与
原串相等
做法 :
对于一个串,找到最大值mmax,最小值进行标记mmin,然后看分别由多少个
mmax 由_mmax记录 ,mmin 由_mmin 记录
然后符合要求的subsequence是
(容斥原理 )包含最大值和最小值的子集的个数 = 总的子集个数 - 只有最小值的子集个数 - 只有最大值的子集的个数 + 既没有最小值又没有最大值的子集的个数
符合要求的substring 是
从0开始枚举
有t1 标记离当前位置最近的mmin下标 ,用t2标记离当前位置最近的mmax下标
然后进行枚举
sum = sum + mmin(t1 +1,t2+1);
PS:当 mmin == mmax 时要特别处理
substring 是 (n*(n+1))/2;
subsequence 是 2^n - 1
**/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <stdio.h>
using namespace std;
#define maxn 100000 + 100
#define mod 1000000007
long long mmap[maxn];
long long _next[maxn];
int main()
{
_next[] = ;
for(int i = ; i < maxn; i++)
{
_next[i] = _next[i - ] * % mod;
}
int T;
scanf("%d", &T);
while(T--)
{
int n;
scanf("%d", &n);
long long mmin = 0xfffffff;
long long mmax = ;
for(int i = ; i < n; i++)
{
scanf("%lld", &mmap[i]);
mmin = min(mmin, mmap[i]);
mmax = max(mmax, mmap[i]);
}
long long sum1 = ;
long long sum2 = ;
if(mmax == mmin)
{
sum1 = ((n * (n + )) / ) % mod;
sum2 = _next[n] - ;
printf("%lld %lld\n", sum1, sum2);
continue;
}
int _mmin = ;
int _mmax = ;
int t1 = -, t2 = -;
for(int i = ; i < n; i++)
{
if(mmap[i] == mmin) {
t1 = i;
_mmin ++;
}
if(mmap[i] == mmax) {
t2 = i;
_mmax ++;
}
sum1 = (sum1 + min(t1 + , t2 + )) % mod;
}
sum2 = (_next[n] - _next[n - _mmin] - _next[n - _mmax] + _next[n - _mmax - _mmin]) % mod;
if(sum2 < ) {
sum2 += mod;
}
printf("%lld %lld\n", sum1, sum2);
}
return ;
}

SPOJ - AMR11H的更多相关文章

  1. Spring-2-H Array Diversity(SPOJ AMR11H)解题报告及测试数据

    Array Diversity Time Limit:404MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Descript ...

  2. SPOJ - AMR11H (容斥原理)

    Enough with this Harry Potter, please! What are we, twelve-year olds?  Let's get our teeth into some ...

  3. 排列组合或容斥原理 SPOJ - AMR11H

    题目链接: https://vjudge.net/contest/237052#problem/H 这里给你一串数字,让你计算同时拥有这串数字最大值和最小值的子集(连续)和子序列(可以不连续)的数量, ...

  4. SPOJ - AMR11H Array Diversity (水题排列组合或容斥)

    题意:给定一个序列,让你求两种数,一个是求一个子序列,包含最大值和最小值,再就是求一个子集包含最大值和最小值. 析:求子序列,从前往记录一下最大值和最小值的位置,然后从前往后扫一遍,每个位置求一下数目 ...

  5. SPOJ - AMR11H Array Diversity (排列组合)

    题意:给定n个数,求包含最大值和最小值的子集(数字连续)和子序列(数字不连续)的个数. 分析: 1.如果n个数都相同,则子集个数为N * (N + 1) / 2,子序列个数为2N-1. 2.将序列从头 ...

  6. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  7. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  8. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  9. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

随机推荐

  1. [译]10个有关SCP的命令

    原文来源: https://www.tecmint.com/scp-commands-examples/ 基本语法 scp source_file_name username@destination_ ...

  2. SQL SERVER 时间相关操作笔记

    1.DATEADD函数: A.  MSDN上的示例:http://msdn.microsoft.com/zh-cn/library/ms186819%28v=sql.90%29.aspx

  3. Qscintilla2编译使用

    Qscintilla2的下载地址: https://github.com/josephwilk/qscintilla https://riverbankcomputing.com/software/q ...

  4. WCF 动态调用(动态创建实例接口)

    很多时候,服务地址都不止一个的,这个时候就要动态去配置地址.配置Web.config,很麻烦 下面就看看怎样实现动态调用WCF. 首先看看动态创建服务对象的代码: using System; usin ...

  5. [剑指Offer] 40.数组中只出现一次的数

    题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. [思路]此题考察的是异或运算的特点:即两个相同的数异或结果为0. 此题用了两次异或运算特点: ( ...

  6. 如何优雅的使用iBatis

    1 使用命名空间2 每张表一个sqlmaps文件3 创建resultMap与parameterMap4 常用的sql创建<sql>片段5 尽量遵循ORM原则设计domain对象

  7. P1268 树的重量

    题目描述 树可以用来表示物种之间的进化关系.一棵“进化树”是一个带边权的树,其叶节点表示一个物种,两个叶节点之间的距离表示两个物种的差异.现在,一个重要的问题是,根据物种之间的距离,重构相应的“进化树 ...

  8. 【BZOJ 2324】[ZJOI2011]营救皮卡丘 费用流

    本人实行诱骗拐卖(利用自然分层与实际意义),正解拼接补充(充分利用最大流限制(不浪费任何一个走出去的机会而不是不浪费任何一个已有的流)与问题转换) #include <cstdio> #i ...

  9. SCOI2008奖励关 [状压dp]

    题目描述 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必须在抛出下一个宝物之前做出选择,且现在决定不吃的宝物以后也不能再 ...

  10. Educational Codeforces Round 58 (Rated for Div. 2) 题解

    Educational Codeforces Round 58 (Rated for Div. 2)  题目总链接:https://codeforces.com/contest/1101 A. Min ...