Codeforces 567C - Geometric Progression - [map维护]
题目链接: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维护]的更多相关文章
- 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
Geometric Progression Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- Codeforces 567C Geometric Progression(思路)
题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak. 感觉很多种做法的样子,我想到这么一种: 枚举中间的aj,看它左边有多少个aj/k右边有多 ...
- CodeForces 567C Geometric Progression 类似dp的递推统计方案数
input n,k 1<=n,k<=200000 a1 a2 ... an 1<=ai<=1e9 output 数组中选三个数,且三个数的下标严格递增,凑成形如b,b*k,b* ...
- 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 ...
- CF 567C Geometric Progression
题目大意:输入两个整数 n 和 k ,接下来输入n个整数组成的序列.求该序列中三个数 满足条件的子串个数(要求字串由三个整数a,b,c组成,其中 c = k * b = k * k * a). 思路: ...
- map Codeforces Round #Pi (Div. 2) C. Geometric Progression
题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...
- 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
C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input stan ...
随机推荐
- 【ARM-Linux开发】嵌入式操作系统上的小型数据库移植SQLite
近段时间在学数据库,因为自身需求,所以注重研究了点嵌入式sqlite数据库,SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品 ...
- Dapper连接MySql数据库
首先通过NuGet在项目中分别安装Dapper和MySql.Data的引用 PM> Install-Package Dapper -Version PM> Install-Package ...
- ROS学习(二)运行keyboard
1.ssh连接机器人 ./dora*.sh 启动roscore,相当于启动ros系统 roscore 2.另启终端,也就意味着重新ssh连接机器人, ./dora*.sh 运行wheel驱动 rosr ...
- vue element-ui typescript tree报错 === Property 'getCheckedNodes' does not exist on type 'Element | Element[] | Vue | Vue[]'.
import { Tree } from 'element-ui' const ref = <Tree>this.$refs.tree ref.getCheckedNodes()
- [转帖]为何 CPU 只用硅,而不用能耗更低的锗制作?知乎好文章
作者:鲁超链接:https://www.zhihu.com/question/28935966/answer/617701106来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- nginx+flask02---概念
概念理解 wsgiref模块是python提供的,用于测试和学习的简单的WSGI服务器模块. 这个模块监听8000端口(监听端口可以改变),把Http请求,根据WSGI协议,转换application ...
- Win10 彻底关闭 Windows Defender
1.使用快捷键 WIN+R 调出运行工具,然后再输入组策略命令 gpedit.msc 再点击确定. 2.进入组策略在计算机配置下面的管理模板,Windows 组件就可以看到 Windows Defen ...
- POJ 2299-Ultra-QuickSort-线段树的两种建树方式
此题有两种建树方式! Description In this problem, you have to analyze a particular sorting algorithm. The algo ...
- 利用Python进行数据分析_Numpy_基础_2
Numpy数据类型包括: int8.uint8.int16.uint16.int32.uint32.int64.uint64.float16.float32.float64.float128.co ...
- 5-6 c语言之【枚举,联合体,递归】
今天学习了枚举,联合体,递归,重点在于递归,所以从网上找到了一些递归的题目进行练习,毕竟程序员界流传一句话,会用循环的是人,会用递归的是神,哈哈哈 还是按次序进行梳理,第一个枚举,枚举和宏定义很相似, ...