当前位置: 代码迷 >> 综合 >> CodeForces 567C Geometric Progression (DP)
  详细解决方案

CodeForces 567C Geometric Progression (DP)

热度:97   发布时间:2023-11-15 11:26:27.0

题目链接:http://codeforces.com/problemset/problem/567/C

DP,注意更新顺序和精度

#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e2+10;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
int gcd(int x,int y){if(y==0) return x;return gcd(y,x%y);
}
map<int,ll> dp[4];
map<int,ll>::iterator it;
int n,x,k;
int main(){cin>>n>>k;rep(i,1,n+1){cin>>x;if(x%k==0) for(int j=3;j>=1;j--) dp[j][x]+=dp[j-1][x/k];///注意顺序dp[1][x]++;///rep cout<<dp[j][1]<<" ";puts("");}ll ans=0;for(it=dp[3].begin();it!=dp[3].end();it++){ans+=(it->se);}cout<<ans<<endl;return 0;
}