题意:
略
思路:
枚举每个值a作为中点,使用两个map来维护a左边和右边的值的情况。
code:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
typedef long long LL;
int n, k;
LL a[N];
map <LL, int> mp, mp2;
void solve() {
mp[a[1]]++;
for(int i = n;i >= 2; i--) mp2[a[i]]++;
LL res = 0;
for(int i = 2;i < n; i++) {
mp2[a[i]]--;
if(a[i]%k == 0 && mp[a[i]/k] != 0 && mp2[a[i]*k] != 0)
res += (LL)mp[a[i]/k]*mp2[a[i]*k];
mp[a[i]]++;
}
printf("%I64d\n", res);
}
int main() {
scanf("%d%d", &n, &k);
for(int i = 1;i <= n; i++) scanf("%I64d" ,&a[i]);
solve();
return 0;
}