B. AND Sequences(证明)

https://codeforces.com/contest/1513/problem/B


思路:不是很会证明,但能直观感受到是最小的相同数才能满足。结合打表猜测。

贴cf的官方证明:

用前缀的方法来证明,其开始要放的数和结尾要放的数一定一样的。

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn];
LL fac[maxn];
map<LL,LL>map1;
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   fac[0]=1;
   for(LL i=1;i<maxn;i++) fac[i]=fac[i-1]*i%mod;
   LL t;cin>>t;
   while(t--){
      LL n;cin>>n;
      map1.clear();
      for(LL i=1;i<=n;i++) cin>>a[i],map1[a[i]]++;
      sort(a+1,a+1+n);
      LL temp1=a[2];
      for(LL i=2;i<=n;i++){
          temp1&=a[i];
      }
      if(temp1!=a[1]){
        cout<<"0"<<"\n";
        continue;
      }
      LL ans=0;
      for(auto i:map1){
          if(i.first==a[1]&&i.second>=2){
            ///cout<<"i.second="<<i.second<<"\n";
            ans=(ans%mod+( ( (i.second%mod*(i.second-1)%mod)%mod)*fac[n-2]%mod)%mod)%mod;
          }
      }
      cout<<ans<<"\n";
   }
   return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值