2道不错的cf题诶

题目链接: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 only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers.

He wants to know how many subsequences of length three can be selected from a, so that they form a geometric progression with common ratio k.

A subsequence of length three is a combination of three such indexes i1, i2, i3, that 1 ≤ i1 < i2 < i3 ≤ n. That is, a subsequence of length three are such groups of three elements that are not necessarily consecutive in the sequence, but their indexes are strictly increasing.

A geometric progression with common ratio k is a sequence of numbers of the form b·k0, b·k1, ..., b·kr - 1.

Polycarp is only three years old, so he can not calculate this number himself. Help him to do it.

Input

The first line of the input contains two integers, n and k (1 ≤ n, k ≤ 2·105), showing how many numbers Polycarp's sequence has and his favorite number.

The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — elements of the sequence.

Output

Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio k.

Sample test(s)
input
5 2
1 1 2 2 4
output
4
input
3 1
1 1 1
output
1
input
10 3
1 2 6 2 3 6 9 18 3 9
output
6
Note

In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4.


题意:有一个长度为n的序列,让你任意取3个数组成等比数列并且公比为k,问你共有多少种情况。


分析:

突然想到一个很好的想法,然后就不小心1A了==。他说取3个数诶,为啥就取3个数嘞。。一开始还傻傻的想如何将一个数的状态转移到别的数。。后来发现其实只需要枚举中间那个数啊,然后看前面有多少个a[i]/k,后面有多少个a[i]*k,然后相乘就是a[i]这个数的贡献额~

p.s.对于pre、suf 的思想是受下面那题影响啦啦啦~

code:

#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define INF 1<<30
typedef long long ll;
const int N = 2e5+10;
ll a[N], pre[N], suf[N];
map 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

D. "Or" Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers byx. We want to make  as large as possible, where  denotes the bitwise OR.

Find the maximum possible value of  after performing at most k operations optimally.

Input

The first line contains three integers nk and x (1 ≤ n ≤ 200 0001 ≤ k ≤ 102 ≤ x ≤ 8).

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

Output

Output the maximum value of a bitwise OR of sequence elements after performing operations.

Sample test(s)
input
3 1 2
1 1 1
output
3
input
4 2 3
1 2 4 8
output
79
Note

For the first sample, any possible choice of doing one operation will result the same three numbers 112 so the result is .

For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 12472 so the OR value will be 79 and is the largest possible result.


题意:一个长度为n的序列,你可以进行k次操作,每次操作可以将序列中的一个数乘以x。问经过k次操作后序列中每个数一起“或”运算一下的最大值是多少。

分析 and code:http://codeforces.com/contest/579/submission/13062876

你可能感兴趣的:(拓展思维题,CodeForces,codeforces,好题,思维题)