CodeForces 567C. Geometric Progression(map 数学啊)
题目链接:http://codeforces.com/problemset/problem/567/C
1 second
256 megabytes
standard input
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.
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 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.
5 2
1 1 2 2 4
4
3 1
1 1 1
1
10 3
1 2 6 2 3 6 9 18 3 9
6
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 数学啊)的更多相关文章
- Codeforces 567C - Geometric Progression - [map维护]
题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中, ...
- CodeForces 567C Geometric Progression
Geometric Progression Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- Codeforces 567C Geometric Progression(思路)
题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak. 感觉很多种做法的样子,我想到这么一种: 枚举中间的aj,看它左边有多少个aj/k右边有多 ...
- CodeForces 567C Geometric Progression 类似dp的递推统计方案数
input n,k 1<=n,k<=200000 a1 a2 ... an 1<=ai<=1e9 output 数组中选三个数,且三个数的下标严格递增,凑成形如b,b*k,b* ...
- 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 ...
- CF 567C Geometric Progression
题目大意:输入两个整数 n 和 k ,接下来输入n个整数组成的序列.求该序列中三个数 满足条件的子串个数(要求字串由三个整数a,b,c组成,其中 c = k * b = k * k * a). 思路: ...
- map Codeforces Round #Pi (Div. 2) C. Geometric Progression
题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...
- Codeforces 567C:Geometric Progression(DP)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
- 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 ...
随机推荐
- 树莓派 Centos7 安装EPEL 7
cat > /etc/yum.repos.d/epel.repo << EOF [epel] name=Epel rebuild for armhfp baseurl=https:/ ...
- CentOS 7 设置开机自启动
创建脚本: #!/bin/bash echo "hello!" # 启动虚拟环境 cd /data/env/crmenv/bin/ source activ ...
- scrollLeft属性设置无效的一个记录
首先应该明确scrollLeft这个属性,只有当div中的内容长度大于当前div的长度是才能working,根据这个我我找到了一个很神奇的地方,而且我注意到这个${}连注释里面都能替换过来! 以下是正 ...
- Saving James Bond - Hard Version
07-图5 Saving James Bond - Hard Version(30 分) This time let us consider the situation in the movie &q ...
- C#基于引用创建单链表
在C语言,单链表的实现依赖指针,指针用来指向节点,那么,用C#实现,自然就想到引用,节点的引用不就类似于指向Node的指针嘛
- 利用scrapy获取抽屉新热榜的标题和内容以及新闻地址保存到本地
1.安装scrapy pip3 install scrapy 2.打开terminal,cd 到想要创建程序的目录下 3.创建一个scrapy项目 在终端输入:scrapy startproject ...
- jmeter-如何进行参数化-循环读取参数
在进行测试的时候,测试数据是一项重要的准备工作,每次迭代的数据当不一样的时候,需要进行参数化,从参数化的文件中来读取测试数据. 本经验主要介绍的是用Csv Data配置元件来进行参数化. 方法/步骤 ...
- .net异步编程async和await的讨论收获
微软官方描述: C# 5 引入了一种简便方法,即异步编程.此方法利用了 .NET Framework 4.5 及更高版本..NET Core 和 Windows 运行时中的异步支持. 编译器可执行开发 ...
- [Go]字典(map)的操作和约束
字典(map)存储的是键值对(key-value pair,一个键值对代表了一对键和值.一个键和一个值分别代表了一个从属于某一类型的独立值,把它们两个捆绑在一起就是键值对,也称“键-元素对”)的集合 ...
- Oracle dataguard failover 实战
Oracle dataguard failover 实战 操作步骤 备库: SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINIS ...