QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#327588 | #3307. Query on a Tree 17 | yinhee | WA | 1ms | 3952kb | C++14 | 2.0kb | 2024-02-15 11:05:08 | 2024-02-15 11:05:08 |
Judging History
answer
// Problem: Split in Sets
// Contest: Virtual Judge - QOJ
// URL: https://vjudge.net/problem/QOJ-1436
// Memory Limit: 253 MB
// Time Limit: 1000 ms
// Written by yinhee.
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define mems(x,y) memset(x,y,sizeof x)
#define Mp make_pair
#define eb emplace_back
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define il inline
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a);i>=(b);i--)
#define go(i,u) for(int i=head[u];i;i=e[i].nxt)
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>inline T read(){
T x=0,f=1;char c=gc();
while(!isdigit(c)){if(c=='-')f=-1;c=gc();}
while(isdigit(c))x=x*10+c-48,c=gc();
return x*f;
}
}
using namespace my_std;
const int N=1e5+7,M=-1,inf=0x3f3f3f3f,mod=1e9+7;
int n,m,a[N],fac[N],ifac[N];
il int binom(int x,int y){return 1ll*fac[x]*ifac[y]%mod*ifac[x-y]%mod;}
il int qpow(int x,int y){
int ret=1;
while(y){
if(y&1)ret=1ll*ret*x%mod;
x=1ll*x*x%mod,y>>=1;
}
return ret;
}
void Yorushika(){
scanf("%d%d",&n,&m);
rep(i,1,n)scanf("%d",&a[i]);
fac[0]=1;
rep(i,1,n)fac[i]=1ll*fac[i-1]*i%mod;
ifac[n]=qpow(fac[n],mod-2);
drep(i,n-1,0)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
sort(a+1,a+n+1);
ll ans=0,res=1;int l=1,r=n;
drep(j,29,0){
int cnt=0;
if(m==1){
int sum=(1<<30)-1;
rep(i,l,r)sum&=a[i];
ans+=sum;break;
}
rep(i,l,r)cnt+=a[i]>>j&1;
if(cnt<=m-1){
rep(i,l,r)if(a[i]>>j&1)ans+=a[i];
res=1ll*res*binom(m,cnt)%mod*fac[cnt]%mod,r-=cnt,m-=cnt;
}else if(cnt==r-l+1){
rep(i,l,r)a[i]-=1<<j;
ans+=1ll*m*(1<<j);
}else{
int sum=(1<<30)-1;
rep(i,l,r)if(!(a[i]>>j&1))sum&=a[i];else a[i]-=1<<j;
ans+=sum+1ll*(m-1)*(1<<j);
res=1ll*res*m%mod,l=r-cnt+1,m--;
}
// printf("%d %lld %d %d %d %d\n",j,ans,cnt,l,r,m);
}
printf("%lld %d\n",ans,res);
}
signed main(){
int t=1;
// scanf("%d",&t);
while(t--)
Yorushika();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3952kb
input:
7 1 6 1 7 7 3 3 2 7 5 5 4 4 1 2 1 4 1 6 2 6 7
output:
0 1
result:
wrong answer 1st lines differ - expected: '2', found: '0 1'