题目描述

Given an array A with length n  a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integer.
Count the number of pair (l,r) such that a[l],a[l+1],...,a[r] can be rearranged to form a geometric sequence.
Geometric sequence is an array where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio. i.e. A = [1,2,4,8,16] is a geometric sequence.

输入描述:

The first line is an integer n (1 <= n <= 100000).
The second line consists of n integer a[1],a[2],...,a[n] where a[i] <= 100000 for 1<=i<=n.

输出描述:

An integer answer for the problem.
示例1

输入

5
1 1 2 4 1

输出

11

说明

The 11 pairs of (l,r) are (1,1),(1,2),(2,2),(2,3),(2,4),(3,3),(3,4),(3,5),(4,4),(4,5),(5,5).
示例2

输入

10
3 1 1 1 5 2 2 5 3 3

输出

20

备注:

The answer can be quite large that you may use long long in C++ or the similar in other languages.

题解

暴力。

先统计公比为$1$的区间有几种,接下来,无论公比为多少,区间长度不会超过$17$,因此只要枚举区间起点,验证$17$个区间即可。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = 100000 + 10;
int n;
long long a[maxn];
long long b[maxn];
int sz; int check() {
if(b[0] == b[sz - 1]) return 0;
if(sz == 2) return 1;
for(int i = 2; i < sz; i ++) {
if(b[1] * b[i - 1] != b[0] * b[i]) return 0;
}
return 1;
} int main() {
while(~scanf("%d", &n)) {
for(int i = 1; i <= n; i ++) {
scanf("%lld", &a[i]);
}
long long ans = 1;
long long sum = 1;
for(int i = 2; i <= n; i ++) {
if(a[i] == a[i - 1]) sum ++;
else sum = 1;
ans = ans + sum;
}
for(int i = 1; i <= n; i ++) {
sz = 0;
for(int j = i; j <= min(n, i + 20); j ++) {
b[sz ++] = a[j];
int p = sz - 1;
while(p && b[p] < b[p - 1]) {
swap(b[p], b[p - 1]);
p --;
}
ans = ans + check();
}
}
printf("%lld\n", ans);
}
return 0;
}

  

湖南大学ACM程序设计新生杯大赛(同步赛)A - Array的更多相关文章

  1. 湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2

    题目描述 Once there was a pig, which was very fond of treasure hunting. One day, when it woke up, it fou ...

  2. 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han

    题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...

  3. 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build

    题目描述 In country  A, some roads are to be built to connect the cities.However, due to limited funds, ...

  4. 湖南大学ACM程序设计新生杯大赛(同步赛)I - Piglet treasure hunt Series 1

    题目描述 Once there was a pig, which was very fond of treasure hunting. The treasure hunt is risky, and ...

  5. 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation

    题目描述 A mod-dot product between two arrays with length n produce a new array with length n. If array ...

  6. 湖南大学ACM程序设计新生杯大赛(同步赛)D - Number

    题目描述 We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), ...

  7. 湖南大学ACM程序设计新生杯大赛(同步赛)H - Yuanyuan Long and His Ballons

    题目描述 Yuanyuan Long is a dragon like this picture?                                     I don’t know, ...

  8. 湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks

    题目描述 BSD is a lazy boy. He doesn't want to wash his socks, but he will have a data structure called ...

  9. 湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?

    题目描述 Two endpoints of two line segments on a plane are given to determine whether the two segments a ...

随机推荐

  1. JavaSE的学习路线

    基于现阶段的JavaEE学习的对象,主要是趋向于Web的方向,主要就是说在JavaWeb的基础上进行进一步的开发和学习,下面我会将自己总结的对于自己的一点关于JavaEE学习路线会逐步讲解. 第一部分 ...

  2. 持久化的基于L2正则化和平均滑动模型的MNIST手写数字识别模型

    持久化的基于L2正则化和平均滑动模型的MNIST手写数字识别模型 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献Tensorflow实战Google深度学习框架 实验平台: Tens ...

  3. Ubuntu+NDK编译openssl

    为了Android上使用libcurl且支持HTTPS协议,需要依赖openssl,因此先来了解一下如何编译OpenSSL1.编译ARM下的共享库(默认的)我使用的是guardianproject的o ...

  4. display:inline-block之用法

    HTML的元素有多种display属性,比较常见的有display:none; display:block; display:inline和display:inline-block;等.详细可参阅W3 ...

  5. lintcode 66.67.68 二叉树遍历(前序、中序、后序)

    AC代码: /** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode le ...

  6. CDN基础详解

    什么是 CDN?     Origin Server: 源站,也就是做 CDN 之前的客户真正的服务器;   User: 访问者,也就是要访问网站的网民;   Edge Server: CDN 的服务 ...

  7. Django【进阶】modelform

    modelform:models+form   建议尽量用Djangoform,更灵活,但也有人用modelform,写起来很简单 缺点,在models里面,表模型必须有__str__()方法 可添加 ...

  8. 56.Merge Intervals---贪心---《编程之美》2.19区间重合判断

    题目链接:https://leetcode.com/problems/merge-intervals/description/ 题目大意:给出一串list,里面装interval类,这个类里有star ...

  9. [转载]FFmpeg完美入门[3] - FFmpeg功能及使用说明

    1 ffplay对多媒体的支持能力验证 一.视频3gp 177X144 支持播放,在windows下播放正常,但是在linux下面偶有BUG 如果发现画面无法显示而声音可以播放的情况下可以试着切换全屏 ...

  10. Python中的raw_input()和input()

    raw_input()和input()都是python中的内建函数,用于读取控制台用户的输入,但有所区别: [nr@localhost conf]$ python Python 2.7.5 (defa ...