Codeforces Round #Pi (Div. 2) C. Geometric Progression map
C. Geometric Progression
Time Limit: 2 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/567/problem/C
Description
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 Input
5 2
1 1 2 2 4
Sample Output
4
HINT
题意
找出 给定序列中 三个数 使得 成等比数列
题解:
枚举中值,map暴力就可以
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include <stack>
typedef __int64 ll;
#define inf 1000000000000
using namespace std;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
} //**************************************************************************************
map<ll ,ll >mp;
map<ll ,ll >mp2;
ll a[];
int main()
{
ll n,k;
scanf("%I64d%I64d",&n,&k);
ll sum=;
ll f1,f2;
for(int i=; i<=n; i++)
{
scanf("%I64d",&a[i]);
if(mp.count(a[i])==)
mp[a[i]]=;
else mp[a[i]]++;
}
if(mp2.count(a[n])==)
mp2[a[n]]=;
else mp2[a[n]]++;
for(int i=n-; i>; i--)
{
if(mp2.count(a[i])==)
mp2[a[i]]=;
else mp2[a[i]]++;
ll t;
if(a[i]==a[i]*k)t=mp2[a[i]*k]-;
else t=mp2[a[i]*k];
if(a[i]%k==)
sum+=((mp[a[i]/k]-mp2[a[i]/k])*(t));
}
cout<<sum<<endl;
return ;
}
Codeforces Round #Pi (Div. 2) C. Geometric Progression map的更多相关文章
- map Codeforces Round #Pi (Div. 2) C. Geometric Progression
题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...
- 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 ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- Codeforces Round #Pi (Div. 2)(A,B,C,D)
A题: 题目地址:Lineland Mail #include <stdio.h> #include <math.h> #include <string.h> #i ...
- codeforces Round #Pi (div.2) 567ABCD
567A Lineland Mail题意:一些城市在一个x轴上,他们之间非常喜欢写信交流.送信的费用就是两个城市之间的距离,问每个城市写一封信给其它城市所花费的最小费用和最大的费用. 没什么好说的.直 ...
- Codeforces Round #Pi (Div. 2) ABCDEF已更新
A. Lineland Mail time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #Pi (Div. 2) —— C-Geometric Progression
题意: 如今有n个数,然后给出一个数k(代表的是等比数列中的那个公比),然后第二行给出n个数,代表的是这个序列. 最后的问题是叫你找出在这个序列中满足公比为k的三个数有几种.并输出方案总数. 思路: ...
- Codeforces Round #392 (Div. 2) F. Geometrical Progression
原题地址:http://codeforces.com/contest/758/problem/F F. Geometrical Progression time limit per test 4 se ...
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set乱搞
D. One-Dimensional Battle ShipsTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
随机推荐
- Js日期选择器并自动加入到输入框中
<html> <head> <title>Js日期选择器并自动加入到输入框中</title> <meta http-equiv="con ...
- sparkR操作HDFS上面的CSV文件
./bin/sparkR --packages com.databricks:spark-csv_2.10:1.3.0 --master yarn hdfs://master:9000/tmp/dem ...
- 数据库客户端SQLeonardo的使用
数据库客户端SQLeonardo的使用 这篇文章要介绍SQLeonardo.我使用了一下,挺不错,一个jar包,加载不同的驱动之后,可以连接很多类型的数据库,我只连接了HSQL和Oracle ...
- Object、Function、String、Array原生对象扩展方法
JavaScript原生对象的api有些情况下使用并不方便,考虑扩展基于Object.Function.String.Array扩展,参考了prototype.js的部分实现,做了提取和修改,分享下: ...
- 移动端Web开发注意点
不用考虑浏览器兼容性 移动端开发主要对象是手持设备,其中绝大部分是IOS和Android系统,so,在开发此类页面时不必纠结IE和其他一些2B浏览器的兼容性,webkit是本次开发重点. 当然,不同版 ...
- POJ 3537 Crosses and Crosses
Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2237 Accepted: 821 Ca ...
- docker commit容器
docker commit 容器ID 镜象REPOSITORY 镜象TAG 如docker commit 52b41c68ac7b registry.lenovows.com:5000/video-a ...
- HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...
- Centos6.5更新e1000网卡驱动
导读 在工作过程中经常遇到linux的操作系统网络不正常的情况,以前没有注意到,今天查看系统日志发现原来是网络驱动的问题.索性直接更新系统,更新网卡 问题:linux系统经常出现断网的情况,重启之后系 ...
- ruby Errors & Exceptions
When you first started coding, errors were probably the last thing you wanted to see. After all, it’ ...