题目链接: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. 2011 luogu P1311 选择客栈

    题目描述 丽江河边有 nn 家很有特色的客栈,客栈按照其位置顺序从 1 到 n 编号.每家客栈都按照某一种色调进行装饰(总共 k 种,用整数 0 ~ k-1 表示),且每家客栈都设有一家咖啡店,每家咖 ...

  2. hdu5126 stars

    题目描述 题解: 和二维的比起来差不多. 但是这是四维偏序. 所以搞一下CDQ套CDQ. CDQ是维度a已经有序,按维度b排序,然后将维度c存入一维数据结构. 所以我们在第一层CDQ中分治处理,将合法 ...

  3. JavaScript 高级技巧 Memoization

    memoization 来源于拉丁语 memorandum ("to be remembered"),不要与 memorization 混淆了. 首先来看一下维基百科的描述: In ...

  4. CSS3---圆角设置

    1.border-radius是向元素添加圆角边框.border-radius:10px; /* 所有角都使用半径为10px的圆角 */     border-radius: 5px 4px 3px ...

  5. Specified VM install not found: type Standard VM, name JDK1.8

    真正的问题解决方法在这里:在项目中,右键点击ant文件,选择Run As -- External Tools Configuration,在这个页面的顶端就会看到有红叉叉的报错,报错信息就是Speci ...

  6. 洛谷 1067 NOIP2009 普及组 多项式输出

    [题解] 一道简单的模拟题.需要判一些特殊情况:第一项的正号不用输出,x的一次项不用输出指数,系数为0的项不用输出等等,稍微细心一下就好. #include<cstdio> #includ ...

  7. Farthest Nodes in a Tree (求树的直径)

    题目链接,密码:hpu Description Given a tree (a connected graph with no cycles), you have to find the farthe ...

  8. LayUI分页基于ASP.NET MVC

    ---恢复内容开始--- 今天写了挺久的分页,百度了很多都没有很好的.Net实例,今天我来更新一期关于layuiTable分页 首先你得理解layui的官方文档的Table分页部分,我在这里附上地址 ...

  9. jmeter-添加断言(检查点)-实例

    方法/步骤     打开 jmeter的图形界面工具,然后打开之前保存的脚本(之前经验中用到的),demo-baidu.jmx   先点击运行,查看运行结果. 第一次请求返回302,然后跳转到第二次请 ...

  10. CodeForces 22、23部分题解

    CodeForces 22A 找严格第二小的...注意只有一种情况,可以sort排序然后unique输出. int a[N]; int main() { int n; while(~scanf(&qu ...