题目链接:http://codeforces.com/problemset/problem/567/C

C. Geometric Progression
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer
k and a sequence a, consisting of
n integers.

He wants to know how many subsequences of length three can be selected from
a, so that they form a geometric progression with common ratio
k.

A subsequence of length three is a combination of three such indexes
i1, i2, i3, that
1 ≤ i1 < i2 < i3 ≤ n. That is, a subsequence of length three are such groups of three elements that
are not necessarily consecutive in the sequence, but their indexes are strictly increasing.

A geometric progression with common ratio k is a sequence of numbers of the form
b·k0, b·k1, ..., b·kr - 1.

Polycarp is only three years old, so he can not calculate this number himself. Help him to do it.

Input

The first line of the input contains two integers, n and
k (1 ≤ n, k ≤ 2·105), showing how many numbers Polycarp's sequence has and his favorite number.

The second line contains n integers
a1, a2, ..., an ( - 109 ≤ ai ≤ 109)
— elements of the sequence.

Output

Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio
k.

Sample test(s)
Input
5 2
1 1 2 2 4
Output
4
Input
3 1
1 1 1
Output
1
Input
10 3
1 2 6 2 3 6 9 18 3 9
Output
6
Note

In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4.

题意:

给定一个数列,要求全部的子序列(顺序一定),是长度为3的等比数列(公比为K)的个数。

PS:

map。

代码例如以下:

#include <cstdio>
#include <cstring>
#include <map>
#include <iostream>
using namespace std;
typedef long long LL; map<int, LL> s1, s2;
int main()
{
LL n, k;
LL ans, x;
cin >> n >> k;
ans = 0;
for(int i = 0; i < n; i++)
{
scanf("%I64d",&x);
if(x%k == 0)
{
LL t1 = s2[x/k];
ans += t1;
LL t2 = s1[x/k];
s2[x] += t2;
}
s1[x]++;
}
cout << ans << endl;
return 0;
}
/*
10 3
1 2 6 2 3 6 9 18 3 9
*/

CodeForces 567C. Geometric Progression(map 数学啊)的更多相关文章

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

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

  2. CodeForces 567C Geometric Progression

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

  3. Codeforces 567C Geometric Progression(思路)

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

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

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

  5. 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 ...

  6. CF 567C Geometric Progression

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

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

    题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...

  8. Codeforces 567C:Geometric Progression(DP)

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

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

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

随机推荐

  1. ios之数据持久化

    9.1 数据持久化概述 iOS中可以有四种持久化数据的方式: 属性列表.对象归档.SQLite3和Core Data 9.2 iOS应用程序目录结构 iOS应用程序运行在Mac os模拟器时候,有一下 ...

  2. Multiplication Puzzle POJ - 1651

    解法 区间dp例题,长度从2开始到n结束起点从1到n,中间枚举的时候是看着左端点右端点与中点的乘积 代码 #include <iostream> #include <cstring& ...

  3. spring-mvc jackson配置json为空不输出

    使用的spring-mvc版本是4.1.6,jackson版本是2.1.4 在spring-mvc配置文件中添加以下代码就行 <mvc:annotation-driven> <mvc ...

  4. 剑指Offer(书):数值的整数次方

    题目:给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 分析: * 要注意以下几点:* 1.幂为负数时,base不能为0,不然求的时候是对 ...

  5. spring的IOC底层原理

    我们调用一个类的方法,首先是User user=new  User(),对象调用这个方法,user.add(),这种方法有一个缺陷就是代码的耦合度太高,比如你的servlet调用User类里的方法,需 ...

  6. LR性能测试问题解决方法

    一.Error -27727: Step download timeout (120 seconds)has expired when downloading resource(s). Set the ...

  7. https://www.cnblogs.com/freeflying/p/9950374.html

    https://www.cnblogs.com/freeflying/p/9950374.html

  8. Leetcode 273.整数转换英文表示

    整数转换英文表示 将非负整数转换为其对应的英文表示.可以保证给定输入小于 231 - 1 . 示例 1: 输入: 123 输出: "One Hundred Twenty Three" ...

  9. N个数求和(模拟)

    本题的要求很简单,就是求N个数字的和.麻烦的是,这些数字是以有理数分子/分母的形式给出的,你输出的和也必须是有理数的形式. 输入格式: 输入第一行给出一个正整数N(≤100).随后一行按格式a1/b1 ...

  10. springboot注释详解

    1.属性注入 @ConfigurationProperties(prefix="...") spring会从classpath下的/config目录或者classpath的根目录查 ...