B. AND Sequences
time limit per test: 2 seconds
memory limit per test: 256 megabytes

A sequence of n non-negative integers (n≥2) a1,a2,…,an is called good if for all i from 1 to n−1 the following condition holds true:
a1&a2&…&ai=ai+1&ai+2&…&an,a_1 \& a_2 \& … \& a_i = a_{i+1} \& a_{i+2} \& … \&a_n, a1​&a2​&…&ai​=ai+1​&ai+2​&…&an​,
where & denotes the bitwise AND operation.

You are given an array a of size n (n≥2). Find the number of permutations p of numbers ranging from 1 to n, for which the sequence ap1,ap2,...,apna_{p1}, a_{p2}, ... ,a_{pn}ap1​,ap2​,...,apn​ is good. Since this number can be large, output it modulo 109+710^9+7109+7.

Input
The first line contains a single integer t (1≤t≤104), denoting the number of test cases.

The first line of each test case contains a single integer n (2≤n≤2⋅105) — the size of the array.

The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109) — the elements of the array.

It is guaranteed that the sum of n over all test cases doesn’t exceed 2⋅105.

Output
Output t lines, where the i-th line contains the number of good permutations in the i-th test case modulo 109+7.

Example
input
4
3
1 1 1
5
1 2 3 4 5
5
0 2 0 3 0
4
1 3 5 1
output
6
0
36
4
Note
In the first test case, since all the numbers are equal, whatever permutation we take, the sequence is good. There are a total of 6 permutations possible with numbers from 1 to 3: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1].

In the second test case, it can be proved that no permutation exists for which the sequence is good.

In the third test case, there are a total of 36 permutations for which the sequence is good. One of them is the permutation [1,5,4,2,3] which results in the sequence s=[0,0,3,2,0]. This is a good sequence because

·s1=s2&s3&s4&s5=0,s_1=s_2\&s_3\&s_4\&s_5=0,s1​=s2​&s3​&s4​&s5​=0,
·s1&s2=s3&s4&s5=0,s_1\&s_2=s_3\&s_4\&s_5=0,s1​&s2​=s3​&s4​&s5​=0,
·s1&s2&s3=s4&s5=0,s_1\&s_2\&s_3=s_4\&s_5=0,s1​&s2​&s3​=s4​&s5​=0,
·s1&s2&s3&s4=s5=0.s_1\&s_2\&s_3\&s_4=s_5=0.s1​&s2​&s3​&s4​=s5​=0.

问题链接:CodeForces - 1513B AND Sequences
问题简述:(略)
问题分析:(略)
AC的C++语言程序如下:

/* CodeForces - 1513B AND Sequences */#include <bits/stdc++.h>using namespace std;typedef long long LL;
const int MOD = 1e9 + 7;
const int N = 2e5;
int a[N];int main()
{int t, n, res;scanf("%d", &t);while (t--) {scanf("%d", &n);scanf("%d", &res);a[0] = res;for (int i = 1; i < n; i++) {scanf("%d", &a[i]);res &= a[i];}LL cnt = 0, ans = 0;for (int i = 0; i < n; i++)if (a[i] == res) cnt++;if (cnt >= 2) {ans = cnt * (cnt - 1) % MOD;for (int i = 1; i <= n - 2; i++)ans *= i, ans %= MOD;}printf("%lld\n", ans);}return 0;
}

CodeForces - 1513B AND Sequences相关推荐

  1. Codeforces - DZY Loves Sequences

    题目链接:Codeforces - DZY Loves Sequences 做一个前后缀连续 LIS ,然后枚举每个位置即可. 注意细节. AC代码: #pragma GCC optimize(&qu ...

  2. Codeforces - 1166D - Cute Sequences

    Codeforces - 1166D - Cute Sequences 地址 http://codeforces.com/contest/1166/problem/D 原文地址 https://www ...

  3. Codeforces 900D Unusual Sequences:记忆化搜索

    题目链接:http://codeforces.com/problemset/problem/900/D 题意: 给定x,y,问你有多少个数列a满足gcd(a[i]) = x 且 ∑(a[i]) = y ...

  4. Codeforces 264B Good Sequences ★ (分解素因子+DP)

    题目链接:http://codeforces.com/problemset/problem/264/B 题目大意:给定一个数列a1,a2,a3,a4,--,an(数据保证ai严格递增,n<=10 ...

  5. codeforces 900D. Unusual Sequences(莫比乌斯反演)

    900D. Unusual Sequences(莫比乌斯反演) 题目链接:传送门 题意: 给出 xxx 和 yyy ,求序列形如 a1,a2..ana_1,a_2..a_na1​,a2​..an​ 满 ...

  6. codeforces:ProblemMset

    最近一个月在codeforces上做的题(做个记录) 后面太多了就不把代码一一放出了,只放置了链接,可根据链接找到提交的代码. 最小子矩阵 #include <iostream> #inc ...

  7. Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences 思维 + 组合数学

    传送门 文章目录 题意: 思路: 题意: 给你d,modd,modd,mod,让你求能构造出如下序列aaa的个数模modmodmod: 思路: 首先可以发现aaa的长度不能超过log2dlog_2dl ...

  8. Vasya and Good Sequences (Codeforces Round #512) 后缀和

    Vasya and Good Sequences (Codeforces Round #512) 后缀和 嘛,蒟蒻第一次写blog,也是第一次用c++好好写程序,多多关照吧 原题: Vasya可以将一 ...

  9. Codeforces 447C - DZY Loves Sequences

    447C - DZY Loves Sequences 思路:dp 代码: #include<bits/stdc++.h> using namespace std; #define ll l ...

最新文章

  1. LINUX UMASK详解
  2. 百度统计 java 实现思路_搞定BAT之百度面经深度整理
  3. Java常用API(六)Date 日期类介绍及使用
  4. NEFU704(AC自动机+状态压缩)
  5. java 没有提示信息,ActionErrors没有提示信息
  6. qt qthead里如何响应信号_Qt 中的多线程技术(翻译)
  7. 想一个颠覆性技术方向建议,你能想到什么?
  8. cocos android 剪切板,Cocos Creator 点击按钮复制到剪切版
  9. Maven : Maven和jenkins报错 ClassNotFoundException : org.slf4j.Logger
  10. pytorch nn.ReLU
  11. Nginx负载均衡和反向代理设置
  12. 单链表的顺序查找c语言,单链表(C语言)
  13. html 超链接嵌套,嵌套的超链接区域,HTML源中没有嵌套的链接元素
  14. FaceBook到底验证个啥?
  15. VS2008显示当前页面的脚本发生错误的处理方法
  16. WooCommerce接入支付宝支付功能(二)——WooCommerce中添加新的支付网关
  17. 干货满满:一位博士在华为的22年
  18. D3D9 简单图形的绘制以及显示
  19. intuitionistic fuzzy set 运算规则python实现
  20. C语言简单的递归程序

热门文章

  1. string转成对象_非常简单的string驻留池,你对它真的了解吗
  2. 2020-05-06 ethtool源代码学习步骤
  3. SQL那些事儿(十一)--ODBC,OLE-DB,ADO.NET区别
  4. PhoneGap的Android端插件开发
  5. Android TTS实现简单阅读器
  6. 用计算机弹假面骑士build,假面骑士build中只有资深粉丝才知道的梗第一弹
  7. 用 man 命令查看 ls 命令的使用手册_Python学习第167课--用man和info打开Linux命令说明书的区别...
  8. Nginx高可用-Keepalived
  9. Intellij IDEA的配置
  10. 计算机tlv简介_TLV编码格式详解