QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472245 | #1436. Split in Sets | zbrc | TL | 3ms | 6972kb | C++14 | 2.1kb | 2024-07-11 15:14:52 | 2024-07-11 15:14:52 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10,mod=1e9+7;
int n,k,ans;
vector<int>a;
int inv[N],fac[N];
int Pow(int x,int n){
if(n==0)return 1;
int a=Pow(x,n/2);
return a*a%mod*(n&1?x:1)%mod;
}
void init(){
inv[0]=fac[0]=1;
for(int i=1;i<N;i++)fac[i]=fac[i-1]*i%mod;
inv[N-1]=Pow(fac[N-1],mod-2);
for(int i=N-2;i;i--)inv[i]=inv[i+1]*(i+1)%mod;
}
int P(int n,int m){
return fac[n]*inv[n-m]%mod;
}
int C(int n,int m){
int res=0;
for(int i=0;i<=m;i++){
if((m-i)&1)res=(res+mod-Pow(i,n)*inv[i]%mod*inv[m-i]%mod)%mod;
else res=(res+Pow(i,n)*inv[i]%mod*inv[m-i]%mod)%mod;
}
return res;
}
int tot=1;
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>k;
init();
tot=tot*P(k,k);
for(int i=1;i<=n;i++){
int x;cin>>x;
a.insert(lower_bound(a.begin(),a.end(),x),x);
}
if(k==1){
ans=a[0];
for(int i=1;i<a.size();i++)ans&=a[i];
cout<<ans<<' '<<1;
return 0;
}
vector<int>e;
for(int i=60;i>=0&&k;i--){
int sum=0,cnt=0;
e.clear();
for(int j=0;j<a.size();j++){
if(a[j]&(1LL<<i)){
cnt++;
sum+=a[j];
e.push_back(a[j]);
}
}
if(i==0){
if(cnt<k)tot=tot*C(a.size()-cnt,k-cnt)%mod;
else tot=C(cnt+1,k)*tot%mod;
}
if(cnt<k){
ans+=sum;
k-=cnt;
for(int j=0;j<e.size();j++){
a.erase(lower_bound(a.begin(),a.end(),e[j]));
}
}else{
if(cnt==a.size()){
ans+=k*(1LL<<i);
for(int j=0;j<e.size();j++){
a.erase(lower_bound(a.begin(),a.end(),e[j]));
a.insert(lower_bound(a.begin(),a.end(),e[j]-(1LL<<i)),e[j]-(1LL<<i));
}
continue;
}
ans+=(k-1)*(1LL<<i);
int s=0,flag=1;
for(int j=a.size()-1;j>=0;j--){
if(lower_bound(e.begin(),e.end(),a[j])==e.end()){
if(flag)s=a[j],flag=0;
else s&=a[j];
a.erase(a.begin()+j);
}
}
a.insert(lower_bound(a.begin(),a.end(),s),s);
for(int j=0;j<e.size();j++){
a.erase(lower_bound(a.begin(),a.end(),e[j]));
a.insert(lower_bound(a.begin(),a.end(),e[j]-(1LL<<i)),e[j]-(1LL<<i));
}
}
}
cout<<ans<<' '<<tot<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 6952kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 3ms
memory: 6612kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 3ms
memory: 6876kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: 0
Accepted
time: 3ms
memory: 6972kb
input:
1000 975 633065 7087 25267 3940676 618039 1695 2043 728466935 3498 13604984 4 99 119488 151315 12 32 52705062 26815 1902279 33952 480604 390647001 60 1 12566875 7591859 6 119892 7829822 2129 4 11644639 17 33200 5330 338 2 9 6862 3781 148087 57 198 13224999 10493180 1 5755424 216 1757297 210 1002623 ...
output:
35467198613 671056390
result:
ok 2 tokens
Test #5:
score: -100
Time Limit Exceeded
input:
99988 19981 11771832 114 110908254 348 553453 840525742 342620766 12408 27914 2 29 4914992 79461083 133 0 44575 11059027 13445407 3508312 227 50410231 1253800 12277 201525297 39 88 20236754 417742 0 8412502 172886086 35315 144742219 211319 352393 10445 1330114 56814394 90807971 3 69704 104497 0 9176...