题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak

感觉很多种做法的样子,我想到这么一种:

  • 枚举中间的aj,看它左边有多少个aj/k右边有多少个aj*k,两边个数的乘积就是答案的一部分贡献。
  • 而左边各个数字的个数和右边各个数字可以用两个map维护,一边枚举一边删除或插入。
 #include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
int a[];
int main(){
map<long long,int> amap,bmap;
int n;
long long k;
scanf("%d%lld",&n,&k);
for(int i=; i<n; ++i){
scanf("%d",a+i);
++bmap[a[i]];
}
long long ans=;
for(int i=; i<n; ++i){
--bmap[a[i]];
if(a[i]%k==){
ans+=(long long)amap[a[i]/k]*bmap[a[i]*k];
}
++amap[a[i]];
}
printf("%lld",ans);
return ;
}

Codeforces 567C Geometric Progression(思路)的更多相关文章

  1. CodeForces 567C Geometric Progression

    Geometric Progression Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

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

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

  3. Codeforces 567C - Geometric Progression - [map维护]

    题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $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. CF 567C Geometric Progression

    题目大意:输入两个整数 n 和 k ,接下来输入n个整数组成的序列.求该序列中三个数 满足条件的子串个数(要求字串由三个整数a,b,c组成,其中 c = k * b = k * k * a). 思路: ...

  6. Codeforces 567C:Geometric Progression(DP)

    time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...

  7. 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 ...

  8. map Codeforces Round #Pi (Div. 2) C. Geometric Progression

    题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...

  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. 对于类的双重调用的demo

    代码如下: package cao.com.duixiang; public class TestCCircle { public static void main(String[] args) { ...

  2. MongoDB csv文件导入导出

    1.导出到csv文件: 2.从csv导入: 数据经过csv导出导入,有一个非常隐蔽的问题,编写代码时需要注意: 先导入一条数据: 其中Price是double类型: 然后我把该条记录导出到Demo.c ...

  3. openURL的使用方法:

    openURL的使用方法: view plaincopy toclipboardprint?        [[UIApplication sharedApplication] openURL:[NS ...

  4. Swift - 开源框架总结

    苹果官方Swift文档<The Swift Programming Language> 苹果开发者Swift文档及介绍 网友整理的Swift中文文档< Apple Swift编程语言 ...

  5. NYOJ题目872开会

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsoAAAKwCAIAAAAOTc6wAAAgAElEQVR4nO3dO3LcSpOG4dkEfS6Edi

  6. JS window.open()属性

    一. Window 对象 Window 对象是 JavaScript 层级中的顶层对象. Window 对象代表一个浏览器窗口或一个框架. Window 对象会在 <body> 或 < ...

  7. Loadrunner中Throughput(吞吐量)的分析与计算

    Throughput翻译为吞吐量,按照常规理解网络吞吐量表示在单位时间内通过网卡数据量之和,其中即包括本机网卡发送出去的数据量也包括本机网卡接收到的数据量,但这个理解在Loadrunner记录的Thr ...

  8. javascript - 浏览器对象

    Navigator对象 弹出窗口 Cookies Browser Objects 参考手册 参考手册描述了每个对象的属性和方法,并提供了在线实例. Window 对象 Navigator 对象 Scr ...

  9. 微信支付 - V3退款

        退款问题: 1.证书加载不进去,出现"内部错误" 解决:在iis中找到对应的应用连接池,右键高级设置,找到"加载用户配置文件"改为true.   2.需 ...

  10. C#的反射机制

    using System; using System.Collections; using System.Collections.Generic; using System.IO; using Sys ...