题目大意:输入两个整数 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. 关于Set Nocount ON的性能 |c#调用存储过程的返回值总是-1

    原文地址:http://www.tuicool.com/articles/qe6BZbR 也许因为它太过于简单,自己一直没能好好关注这个语句,只记得"只是"提高点性能而已.有时会在存储过程中写上几句, ...

  2. cocos2dx-lua绑定自定义c++类(二)

    在 cocos2dx-lua绑定自定义c++类(一)中介绍了如何产生绑定文件. 现在,来看看怎么在工程里使用这个cpp文件.像普通源码文件一样,导入到工程里,看到 LuaTest.h文件里有一个函数入 ...

  3. Java高级软件工程师面试考纲

    如果要应聘高级开发工程师职务,仅仅懂得Java的基础知识是远远不够的,还必须懂得常用数据结构.算法.网络.操作系统等知识.因此本文不会讲解具体的技术,笔者综合自己应聘各大公司的经历,整理了一份大公司对 ...

  4. javascript笔记6之函数

    /* function box() { //函数的声明 alert('我只有被调用才可以执行!'); //函数本身没有运行功能 } //必须调用才可以执行 box(); //调用 function b ...

  5. poj 2441 Arrange the Bulls(状态压缩dp)

    Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to ...

  6. curl 学习

    <?php // $username =13800138000; // $password =123456; // $sendto =13912345678; // $message = &qu ...

  7. Webservice-Java-Xfire

    最近公司最近需要将以前提供出去的接口统一用一个标准来实现,考虑到webservice这个是标 准,因此我花时间大概学习了一下webservice,也对JAVA的几个webservice框架进行了一些小 ...

  8. 全响应跨设备的Zoomla!逐浪CMS2 x2.0正式公布

    2014年是中国互联网的重要一年,京东上市.聚美优品领衔创业风范,小米进军国际化.滴滴快的锋火争雄. 作为中国互联网的中间力量,Zoomla!逐浪软件团队坚守信念,始终以WEB开发和科研创新为己任,并 ...

  9. leetcode:Minimum Path Sum(路线上元素和的最小值)【面试算法题】

    题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right w ...

  10. mysql三种binlog日志的理解

    最近,一直在纠结要不要改数据库binlog的日志格式,原先用的是row格式,导致数据库binlog日志较大,磁盘空间本来也不是很大,所以就想看看能不能改变binlog日志.在该binlog日志之前,先 ...