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 ...
随机推荐
- Netbeans连接数据库
/* Netbeans连接数据库 NetBeans项目的“项目属性”中“库”一栏中.Tab页“编译和运行”中已经加上jdbc的驱动文件 */ Connection conn = null;//连接数据 ...
- Linux中iptables设置详细(转)
无论如何,iptables是一个需要特别谨慎设置的东西,万一服务器不在你身边,而你贸然设置导致无法SSH,那就等着被老板骂吧,呵呵... 以下内容是为了防止这种情况发生而写的,当然很初级,不过一般服务 ...
- SilverLight 条码 扫描枪 MVVM(转载)
目前做SL项目时,遇到条码的问题. 客户需要通过条码来加快工作效率以及减少错误.有条码,自然便引入扫描枪这个东西.不解释. 关键点是:扫描枪每次扫描完毕会触发回车 这是解决问题的关键! 现有两种情景: ...
- Hibernate unsaved-value 属性
Session的saveOrUpdate方法是由Hibernate来判断被操作对象究竟是一个持久化对象还是临时自由状态对象.这需要在对象映射文件的主键id中定义unsaved-value属性,如果不显 ...
- 使用stty修改终端设置 stty 用法!
在linux/unix平台上的 sqlplus中,如果输错了字符,要想删除,习惯性的按下backspace键后,发现非但没有删除想要删掉的字符,还多出了两个字符^H.当然,我们 可以同时按下ctrl+ ...
- JS的运行机制
代码块: JS中的代码块是指由<script>标签分割的代码段.JS是按照代码块来进行编译和执行的,代码块间相互独立(即就算代码块1出错,但不影响代码块2的加载和执行),但变量和方法共享. ...
- shell kill掉含同一字符的关键字的进程
如何kill掉进程名包含某个字符串的一批进程:kill -9 $(ps -ef|grep 进程名关键字|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ') 观 ...
- magic-encoding
(文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 今天页面跳转都出问题了,各种方法都试过了, log里说语法错误,问了pp,他说是汉字的原因...果 ...
- Coursera台大机器学习技法课程笔记03-Kernel Support Vector Machine
这一节讲的是核化的SVM,Andrew Ng的那篇讲义也讲过,讲的也不错. 首先讲的是kernel trick,为了简化将低维特征映射高维特征后的计算,使用了核技巧.讲义中还讲了核函数的判定,即什么样 ...
- Nginx反向代理的目录访问问题
Nginx反向代理的目录访问问题 2013-05-13 23:21 2730人阅读 评论(0) 收藏 举报 从昨天就开始纠结了,在做实验的时候,遇到目录访问的问题,如下 前端nginx vhost的设 ...