题目链接:http://codeforces.com/problemset/problem/567/C
分析:
突然想到一个很好的想法,然后就不小心1A了==。他说取3个数诶,为啥就取3个数嘞。。一开始还傻傻的想如何将一个数的状态转移到别的数。。后来发现其实只需要枚举中间那个数啊,然后看前面有多少个a[i]/k,后面有多少个a[i]*k,然后相乘就是a[i]这个数的贡献额~
p.s.对于pre、suf 的思想是受下面那题影响啦啦啦~
code:
#include<stdio.h>
#include<string.h>
#include<set>
#include<map>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define INF 1<<30
typedef long long ll;
const int N = 2e5+10;
ll a[N], pre[N], suf[N];
map<ll,ll> m;
int main()
{
int n, k;
scanf("%d%d", &n,&k);
for(int i=1; i<=n; i++)
{
scanf("%lld", a+i);
}
for(int i=1; i<=n; i++)
{
if(a[i]%k == 0) pre[i] = m[a[i]/k];
m[a[i]]++;
}
m.clear();
for(int i=n; i>=1; i--)
{
if(a[i]%k == 0) suf[i] = m[a[i]*k];
m[a[i]]++;
}
ll res = 0;
for(int i=2; i<=n-1; i++)
res += pre[i]*suf[i];
printf("%lld\n", res);
return 0;
}
题目链接:http://codeforces.com/contest/579/problem/D
分析 and code:http://codeforces.com/contest/579/submission/13062876