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 ...
随机推荐
- python 全栈开发之旅
目录 python 基础语法 python 数据类型(未完成) python 内置函数(未完成) python 常用标准库(未完成) python 类(未完成) python 进程.线程.协程(未完成 ...
- Hyper-V VM Generation 2 - Can not boot from .ISO (Hyper-V Gen2不能從DVD啓動 ISO)
Q: Hyper-V VM Generation 2 - Can not boot from .ISO (Hyper-V Gen 2不能從DVD啓動 ISO ) A: Disable secure ...
- Mac安装7Z以及Mac下查看隐藏文件夹
一:Mac下安装7Z: 1:brew直接安装解压工具 $ brew search 7z 会搜索到: ==> Formulae p7zip 2:$ brew install p7zip ...
- java类加载全过程
引用:http://blog.csdn.net/haluoluo211/article/details/49908463 http://www.cnblogs.com/pengfeiliu/p/442 ...
- [转载]桥接与NAT
NAT相当于是局域网中的局域网,把192.168.21.1当作外网ip,重新划分了一个网关(192.168.33.x) 网桥只是把网络桥接起来,还是原来的网关(192.168.21.x),虚拟机相当于 ...
- java连接zookeeper实现zookeeper的基本操作
Java服务端连接Zookeeper,进行节点信息的获取,管理…,整理成一个基本工具, 添加依赖: <dependency> <groupId>org.apache.zooke ...
- 浅谈UML的概念和模型
讲了UML的基本的九种图:http://blog.csdn.net/jiuqiyuliang/article/details/8552956 来具体讲讲这九种视图: 1.用例图(use case di ...
- 『Linux』第二节: 安装Linux系统
一. 准备工具 1. centOS系统下载 http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1810.is ...
- HDU4641 K-string(后缀自动机+线段树合并)
先考虑没有动态加字符怎么做.计算每个节点的贡献,当|right|>=k时将len-lenfa计入即可. 动态加字符后,这个东西难以用LCT维护.于是考虑离线.建完SAM后,容易发现每个节点在时间 ...
- sql 时间获取
现在时间:GETDATE() 昨天时间:CONVERT(VARCHAR(16),DATEADD(d,-1,GETDATE()),120)