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

题意:

给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中,长度为 $3$ 的等比子序列的数目。

题解:

首先倒着遍历,用map记录曾经出现过的每个数字的出现次数,然后再用另一个map来记录曾经出现过的所有满足 $(x,kx)$ 的二元组的数目,最后就直接维护答案即可。

AC代码:

#include<bits/stdc++.h>
#define IO (ios::sync_with_stdio(0),cin.tie(0),cout.tie(0))
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int maxn=2e5+;
int n;
ll k,a[maxn];
map<ll,ll> mp1;
map<P,ll> mp2; int main()
{
IO; cin>>n>>k; ll mx=-1e10, mn=1e10;
for(int i=;i<=n;i++)
cin>>a[i], mx=max(a[i],mx), mn=min(a[i],mn); ll ans=;
for(int i=n;i>=;i--)
{
if(mn/(k*k)<=a[i] && a[i]<=mx/(k*k))
ans+=mp2[mk(a[i]*k,a[i]*k*k)]; if(mn/k<=a[i] && a[i]<=mx/k)
mp2[mk(a[i],a[i]*k)]+=mp1[a[i]*k]; mp1[a[i]]++;
}
cout<<ans<<endl;
}

Codeforces 567C - Geometric Progression - [map维护]的更多相关文章

  1. CodeForces 567C. Geometric Progression(map 数学啊)

    题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...

  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. Centos7之pacemaker高可用安装配置详解

    申明: centos7的pacemaker与6使用的方法不一致,即使用centos6.x的方法在centos7.x上面配置pacemaker不能成功. 因此openstack 上面的centos7.1 ...

  2. 字符串匹配算法---BF

    Brute-Force算法,简称BF算法,是一种简单朴素的模式匹配算法,常用语在一个主串string 内查找一个子串 pattern的出现位置. 核心思想: i 遍历主串string i 每自增一次, ...

  3. vue-cli2和vue-cli3同时存在

    https://blog.csdn.net/Jioho_chen/article/details/90455778 win下 vue-cli2 和 vue-cli3 并存,一起使用开局一张图,内容慢慢 ...

  4. 如何保持人际关系zz

    作者:Faaany链接:https://www.zhihu.com/question/35590289/answer/63675007来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...

  5. python学习-50 pickle模块

    pickle模块 与json方法是一样的 import pickle dic = {'} print(type(dic)) a = pickle.dumps(dic) print(type(a)) f ...

  6. python学习-48 模块2

    sys修改环境变量 ---------- 只能临时修改 import syssys.path.append() 例如: import sys sys.path.append('C:\Users\hua ...

  7. python学习-34 内置函数的补充

    其他内置函数 1.ord()    与chr()相反 2.pow() print(pow(3,3)) # 相当于3**3 print(pow(3,3,2)) # 相当于3*3%2 运行结果: 27 1 ...

  8. 『Linux』第二节: 安装Linux系统

    一. 准备工具 1. centOS系统下载 http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1810.is ...

  9. 少儿编程 | 02.Scratch编程环境

    上次课程介绍了Scratch的基本概念和一些特点,最后还给出了一些有趣的例子.本次课程介绍Scratch的两种编程环境以及在Scratch官网注册个人账号的步骤. Scratch 3.0的两种编程环境 ...

  10. SVM的概率输出(Platt scaling)

    SVM的概率输出(Platt scaling) 2015-10-22 10:38:19 闲渔Love吉他 阅读数 8121 文章标签: Platt Scaling Calibr 更多 分类专栏: 计算 ...