Codeforces 567C Geometric Progression(思路)
题目大概说给一个整数序列,问里面有几个包含三个数字的子序列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(思路)的更多相关文章
- CodeForces 567C Geometric Progression
Geometric Progression Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- CodeForces 567C. Geometric Progression(map 数学啊)
题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...
- Codeforces 567C - Geometric Progression - [map维护]
题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中, ...
- CodeForces 567C Geometric Progression 类似dp的递推统计方案数
input n,k 1<=n,k<=200000 a1 a2 ... an 1<=ai<=1e9 output 数组中选三个数,且三个数的下标严格递增,凑成形如b,b*k,b* ...
- CF 567C Geometric Progression
题目大意:输入两个整数 n 和 k ,接下来输入n个整数组成的序列.求该序列中三个数 满足条件的子串个数(要求字串由三个整数a,b,c组成,其中 c = k * b = k * k * a). 思路: ...
- 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 map
C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- 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 ...
随机推荐
- August 11th 2016, Week 33rd Thursday
A particular fine spring came around. 转眼又是一番分外明媚的春光. Hey, it is hot outside, sometimes even unbearab ...
- 解决spring+shiro cacheManager 登录报错
一.项目启动,登录报错 org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' ...
- iOS小技巧总结,绝对有你想要的
原文链接 在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIV ...
- 1.Windows安装PostgreSQL
按照下面的步骤,Windows机器上安装PostgreSQL.请确保已开启第三方防病毒,同时安装. 挑选你想要的PostgreSQL的版本号,可以点击以下链接下载 EnterpriseDB Windo ...
- IOS常用正则表达式
IOS常用正则表达式 正则表达式用于字符串处理.表单验证等场合,实用高效.现将一些常用的表达式收集于此,以备不时之需. 匹配中文字符的正则表达式: [\u4e00-\u9fa5] 评注:匹配中文还真是 ...
- 《AngularJS》5个实例详解Directive(指令)机制
本文整理并扩展了<AngularJS>这本书第六章里面的内容,此书近期即将由电子工业出版社出版,敬请期待口令:Angular 1.一点小说明 指令的作用:实现语义化标签 我们常用的HTML ...
- html5 离线存储 worker
html5 离线存储 <!DOCTYPE html> <html manifest="cache.manifest"> <!--manifest存储- ...
- android 入门-R文件的死与活
1.图片的名字Btn_Play R文件死了. 1.答:修改图片的名字btn_play R文件活了.
- W:Failed to fetch http://archive.ubuntukylin.com:10006/ubuntukylin/dists/pre
由于用ubuntu的时候装了几个ubuntukylin的软件(像搜狗拼音for linux),于是最近总是蹦出一个红色的三角提示,说无法更新,虽说不影响使用但是还是很不爽.解决方法记录如下: 进入系统 ...
- 命令模式/command模式/行为型模式
举个栗子 指挥官向士兵下达命令,士兵执行 实现代码如下: class Soldier { public void exe() { System.out.println("执行命令" ...