题目大意:输入两个整数 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. Raid1源代码分析--读流程

    这篇博文不足之处较多,重新整理了一下,链接:http://www.cnblogs.com/fangpei/p/3890873.html 我阅读的代码的linux内核版本是2.6.32.61.刚进实验室 ...

  2. poj 3666 Making the Grade(dp)

    Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...

  3. fcntl函数加文件锁

    对文件加锁是原子性的,可以用于进程间文件操作的同步.在linux下,有三个函数可以对文件进程加锁,分别是fcntl.flock.lockf.这里只说fcntl,它的用法也是最复杂的. fcntl是fi ...

  4. 使用MutationObserver对象封装一个监听DOM生成的函数

    (function(win){ 'use strict'; var listeners = []; var doc = win.document; var MutationObserver = win ...

  5. PHP设计模式笔记七:观察者模式 -- Rango韩老师 http://www.imooc.com/learn/236

    观察者模式 概述: 1.观察者模式(Observer),当一个对象状态发生改变时,依赖他的对象全部会收到通知,并自动更新 2.场景:一个事件发生后,要执行一连串更新操作,传统的编程方式,就是在事件的代 ...

  6. Servlet实现文件的下载

    (1)项目的主文件夹例如以下:(演示出image和servlet的位置所在) watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGxnZW4xNTczODc= ...

  7. Windows7 32位机上,OpenCV中配置GPU操作步骤

    1.  查看本机配置,查看显卡类型是否支持NVIDIA GPU: 2.  从http://www.nvidia.cn/Download/index.aspx?lang=cn下载最新驱动并安装: 3.  ...

  8. 【leetcode】Merge Sorted Array(合并两个有序数组到其中一个数组中)

    题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assum ...

  9. Android自定义控件(四)——让每一个Activity UI都具有弹性

    前面我们已经介绍了如何让你的ScrollView,ListView具有弹性, 今天,我们在前面的基础上,做一下适当的修改,让那些既不是ScrollView,也不是ListView的Activity页面 ...

  10. ORA-24324、ORA-12560、ORA-12514

    SQL> startup ERROR: ORA-24324: 未初始化服务句柄 ORA-01041: 内部错误, hostdef 扩展名不存在. SQL> conn sys /nolog; ...