QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#470754#1436. Split in SetshyxleWA 8ms9480kbC++202.8kb2024-07-10 16:13:492024-07-10 16:13:49

Judging History

你现在查看的是最新测评结果

  • [2024-07-10 16:13:49]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:9480kb
  • [2024-07-10 16:13:49]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define R register
using namespace std;
const int N=1e5+5,mod=1e9+7;
ll n,k,a[N],res1,res2=1,mul[N],inv[N];
vector<int> v;
inline ll qmul(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=(a*a)%mod;b>>=1;
    }
    return ans;
}
inline void init(int _n){
    inv[0]=mul[0]=1;
    for(R int i=1;i<=_n;++i)mul[i]=mul[i-1]*i%mod;
    inv[_n]=qmul(mul[_n],mod-2);
    for(R int i=_n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%mod;
}
inline ll C(ll a,ll b){
    if(a<b||b<0||a<0)return 0;
    return mul[a]*inv[b]%mod*inv[a-b]%mod;
}
inline void solve(int len,int cntk,int t){
    if(t<0||!len)return;
    if(cntk==1){
        int res=v[0];
        for(R int i=1;i<len;++i)res&=v[i];
        res1+=res;
        return;
    }
    // cout<<len<<' '<<cntk<<'\n';
    vector<int> v1;int cnt=0;
    for(R int i=0;i<len;++i){
        v1.push_back(v.back());int kk=v.back();v.pop_back();
        if((kk>>t)&1)++cnt;
    }
    if(!cnt){
        for(R int i=0;i<len;++i){
            v.push_back(v1.back());v1.pop_back();
        }
        solve(len,cntk,t-1);
        return;
    }
    if(cnt<cntk){
        res2=(res2*mul[cntk]%mod*inv[cntk-cnt])%mod;
        for(R int i=0;i<len;++i){
            int kk=v1.back();v1.pop_back();
            if((kk>>t)&1){
                res1+=kk;--k;
            }
            else v.emplace_back(kk);
        }
        solve(v.size(),cntk-cnt,t-1);
    }else if(cnt==cntk){
        for(R int i=0;i<len;++i){
            res1+=v1[i];
            // cout<<v1[i]<<' ';
        }
        res2=res2*mul[cntk]%mod*inv[cntk-cnt]%mod;
        cout<<res1<<' '<<res2;exit(0);
    }else if(cnt==len&&cnt>cntk){
        res1+=(1<<t)*(cntk);
        for(R int i=0;i<len;++i){
            int kk=v1.back();
            if((kk>>t)&1){
                kk^=(1<<t);
                v.push_back(kk);
            }
            v1.pop_back();
        }
        solve(v.size(),cntk,t-1);
    }else{
        res1+=(1<<t)*(cntk-1);
        int res=0;bool fl=0;
        for(R int i=0;i<len;++i){
            int kk=v1.back();
            if((kk>>t)&1){
                kk^=(1<<t);
                v.push_back(kk);
            }else{
                if(!fl)fl=1,res=kk;
                else res&=kk;
            }
            v1.pop_back();
        }
        v.push_back(res);
        solve(v.size(),cntk,t-1);
    }
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
    cin>>n>>k;init(max(n,k));
    for(R int i=1;i<=n;++i)cin>>a[i],v.emplace_back(a[i]);
    solve(n,k,30);ll sum=0;
    for(R int i=0;i<=k;++i){
        ll kk=(i%2==0?1:mod-1)*C(k,i)%mod;
        sum=(sum+kk*qmul(k-i,v.size()))%mod;
    }
    res2=(res2*sum)%mod;
    cout<<res1<<' '<<res2<<'\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

3 2
4 7 5

output:

11 2

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

4 1
44 47 74 77

output:

8 1

result:

ok 2 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

4 4
44 47 74 77

output:

242 24

result:

ok 2 tokens

Test #4:

score: 0
Accepted
time: 1ms
memory: 3720kb

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
Wrong Answer
time: 8ms
memory: 9480kb

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...

output:

3435071737284 430589528

result:

wrong answer 1st words differ - expected: '3435071736287', found: '3435071737284'