题目大意:输入两个整数 n 和 k ,接下来输入n个整数组成的序列。求该序列中三个数 满足条件的子串个数(要求字串由三个整数a,b,c组成,其中 c = k * b = k * k * a)。

思路:枚举中间的数,然后分别求出前面和后面满足条件的数的个数,将两数相乘,然后累加积即可。

  由于题目中给出的数据范围较大,且有负数,故用MAP来影射输入的序列中的每个元素。

代码:

  #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
#define INF 0x7fffffff map<long long,long long> m;
long long n,k,a[200001],pre[200001],late[200001];
long long sum;
int main(){
while(~scanf("%I64d%I64d",&n,&k)){
int i;
m.clear();
sum = 0;
memset(pre,0,sizeof(pre));
memset(late,0,sizeof(late)); for(i=1;i<=n;i++){
scanf("%I64d",&a[i]);
if(!m[a[i]])
m[a[i]] = i;
}
pre[m[a[1]]] ++ ;
for(i=2;i<=n;i++)
late[m[a[i]]] ++ ;
for(i=2;i<n;i++){
late[m[a[i]]] -- ;
double t = a[i]*1.0 / k;
long long x = t;
if(t != x){
pre[m[a[i]]] ++ ;
continue ;
}
sum += pre[m[x]] * late[m[x*k*k]] ;
pre[m[a[i]]] ++ ;
}
printf("%I64d\n",sum);
} return 0;

}

CF 567C Geometric Progression的更多相关文章

  1. CodeForces 567C Geometric Progression

    Geometric Progression Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  2. CodeForces 567C. Geometric Progression(map 数学啊)

    题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...

  3. CF 567C(Geometric Progression-map)

    C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces 567C Geometric Progression(思路)

    题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak. 感觉很多种做法的样子,我想到这么一种: 枚举中间的aj,看它左边有多少个aj/k右边有多 ...

  5. CodeForces 567C Geometric Progression 类似dp的递推统计方案数

    input n,k 1<=n,k<=200000 a1 a2 ... an 1<=ai<=1e9 output 数组中选三个数,且三个数的下标严格递增,凑成形如b,b*k,b* ...

  6. Codeforces 567C - Geometric Progression - [map维护]

    题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中, ...

  7. Codeforces 567C:Geometric Progression(DP)

    time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...

  8. Codeforces Round #Pi (Div. 2) C. Geometric Progression map

    C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  9. hdu 5278 Geometric Progression 高精度

    Geometric Progression Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contes ...

随机推荐

  1. Enum Types

    参考Java的官方tutorial和Doc整理如下. What is Enum An enum type is a special data type. It enables for a variab ...

  2. 关于我们-EIBOA易博男装-互联网品质男装品牌-在线销售男士西服,衬衫,外套,西裤,领带|全场免运费,30天退换货保障

    关于我们 - 网站底部 | ELLE中国 | ELLE China 关于赫斯特国际集团 男人尚--专注男人时尚 关于男人尚 这些数据,你知道吗? 1.全国至少1亿男人的衬衫尺码错误: 2.57%的男人 ...

  3. c语言typedef运用与函数指针

    #include <stdio.h> #include <stdlib.h> #define PINT int * typedef short* PSHORT; //typed ...

  4. Java中判断集合类为空的方法

    *****需要引入Spring的核心Jar包***** 工具类: org.springframework.util.CollectionUtils 方法: public static boolean ...

  5. css中的边框样式

    在盒子模型中,盒子的边框是其重要的样式,通过边框我们可以很方便地看出盒子的长宽以及大小.边框的特性可以通过边框线,边框的宽度及颜色来呈现. 1,边框线 边框线指的是边框线条的样式,包括实线,虚线,点划 ...

  6. Android 之 Shape (圆角输入框)

    1 简介 本文主要介绍通过 shape 来设置 EditText 的圆角.   2 shape 的设置   shape_life_search.xml 放在 res/drawable 文件夹内 < ...

  7. 【InversionCount 逆序对数 + MergeSort】

    Definition of Inversion: Let (A[0], A[1] ... A[n], n <= 50) be a sequence of n numbers. If i < ...

  8. Window vagrant 安装部署【转】

    回想以前,想要安装个虚拟机是多么的麻烦.先要费尽心机找到想要的操作系统镜像文件,然后安装虚拟化软件,按照其提供的GUI界面操作一步步创建,整个过程费时费力.但是,自从使用了Vagrant以后,咱腰不酸 ...

  9. 图像重采样(CPU和GPU)

    1 前言 之前在写影像融合算法的时候,免不了要实现将多光谱影像重采样到全色大小.当时为了不影响融合算法整体开发进度,其中重采样功能用的是GDAL开源库中的Warp接口实现的. 后来发现GDAL War ...

  10. c#基础: 线程的初级用法总结

    启动一个线程的两种方法:     a.使用无参的方法       Thread thread1 = new Thread(new ThreadStart("调用的方法名")):   ...