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 9th 2016, Week 33rd Tuesday
Tomorrow is never clear, our time is here. 明天是未知的,我们还是要过好当下. Tomorrow is not unpredictable, it is cl ...
- jieba
# coding: utf-8 # ###jieba特性介绍 # 支持三种分词模式: # 精确模式,试图将句子最精确地切开,适合文本分析: # 全模式,把句子中所有的可以成词的词语都扫描出来, 速度非 ...
- NYOJ题目768移位密码
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtIAAAJqCAIAAACJkTDlAAAgAElEQVR4nO3du3Ljvpa34b4J574Qx7
- 三、jQuery--jQuery插件--jQuery插件——Validation Plugin
简介: 客户端验证:现代网站填写表单时,几乎一定会采用的方式. 优点:1.可以减少服务器压力 2.缩短用户等待时间和提升用户体验 jQuery有很多表单验证插件:https://plugins.jqu ...
- 三、jQuery--jQuery基础--jQuery基础课程--第5章 jQuery 操作DOM元素
1.使用attr()方法控制元素的属性 attr()方法的作用是设置或者返回元素的属性,其中attr(属性名)格式是获取元素属性名的值,attr(属性名,属性值)格式则是设置元素属性名的值. 例如,使 ...
- Redis不同数据类型的的数据结构实现
我们知道Redis支持五种数据类型, 分别是字符串.哈希表(map).列表(list).集合(set)和有序集合,和Java的集合框架类似,不同数据类型的数据结构实也是不一样的. >>Re ...
- scrollTop和scrollLeft的兼容解决万全方法
1.各浏览器下 scrollTop的差异 IE6/7/8: 对于没有doctype声明的页面里可以使用 document.body.scrollTop 来获取 scrollTop高度 : 对于有do ...
- Web API 使用上安全吗?
Web API入门指南有些朋友回复问了些安全方面的问题,安全方面可以写的东西实在太多了,这里尽量围绕着Web API的安全性来展开,介绍一些安全的基本概念,常见安全隐患.相关的防御技巧以及Web AP ...
- golang channel basic
package mainimport ( "fmt" "math/rand" "time")func main() { rand.Seed( ...
- 5-06使用Sql 语句为表添加约束
约束名的命名规则推荐采用:约束类型_约束列. 为用户表添加约束 ALTER TABLE UserInfo ADD CONSTRALNT PK_UserId PRIMATY REY(UserId) CO ...