codeforces 567C

求长度为三的子序列是公比为k的等比数列的个数

很好想到思路,,,,就是记录之前的数中,是这个数的1/k的有多少个,1/k^2的有多少个,,,,,

主要就是数字太大不能用数组,,,要用map(涨姿势)

#include<stdio.h>

#include<string.h>

#include <algorithm>

#include <bits/stdc++.h>

using namespace std;

long long int a;

map<long long int,long long int>c1,c2;

int main()

{

int m,k;

scanf("%d%d",&m,&k);

int i;

long long int ans=0;

for(i=0;i<m;i++)

{

scanf("%lld",&a);

if(a%(k*k)==0) ans+=c1[a/k]; //作为了第三个数

if(a%k==0) c1[a]+=c2[a/k]; //作为了第二个数

c2[a]++; //肯定有机会作为后面的第一个数

}

printf("%lld\n",ans);

return 0;

}



版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-07 01:21:07

codeforces 567C的相关文章

CodeForces 567C Geometric Progression

Geometric Progression Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 567C Description Polycarp loves geometric progressions very much. Since he was only three years old, he loves only t

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

题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp loves geometric progressions very much. Since he was on

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 (i

CodeForces 567C Geometric Progression 类似dp的递推统计方案数

input n,k 1<=n,k<=200000 a1 a2 ... an 1<=ai<=1e9 output 数组中选三个数,且三个数的下标严格递增,凑成形如b,b*k,b*k*k的种数 做法:先将可以作为第三个数的数放到map中,然后再扫一遍依次统计map中的数作为第三个数的种数,第二个数的种数,第三个数的种数 1 #include<cstdio> 2 #include<map> 3 struct node 4 { 5 int b;//a[i]作为i1的

Codeforces 567A 567B 567C 567D

A. Lineland Mail time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi - a coordi

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st