QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419717#8723. 乘二debateWA 62ms12848kbC++142.1kb2024-05-24 10:22:122024-05-24 10:22:13

Judging History

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

  • [2024-05-24 10:22:13]
  • 评测
  • 测评结果:WA
  • 用时:62ms
  • 内存:12848kb
  • [2024-05-24 10:22:12]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn=1e6+50;
const ll mod=1e9+7;
ll n,k;
ll a[maxn],pos[maxn];
ll check(ll x){
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=max(0ll,x-pos[i]);
    }
    if(ans<=k) return 1;
    return 0;
}
ll ksm(ll base,ll b){
    ll ans=1;
    while(b){
        if(b&1){
            ans*=base;
            ans%=mod;
        }
        base*=base;
        base%=mod;
        b>>=1;
    }
    return ans%mod;
}
struct node{
    ll val,pos;
}ps[maxn];
vector<pair<ll,ll>> v;
bool cmp(node x,node y){
    return x.val<y.val;
}
int main(){
    cin>>n>>k;
    ll mx=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        for(int j=31;j>=0;j--){
            if((a[i]&(1ll<<j))){
                pos[i]=j;
                mx=max(mx,pos[i]);
                break;
            }
        }
    } 
    ll l=0,r=k+31;
    while(l<r){
        ll mid=(l+r+1)>>1;
        if(check(mid)){
            l=mid;
        }
        else r=mid-1;
    }
    //cout<<"l="<<l<<endl;
    ll s=k;
    for(int i=1;i<=n;i++){
        s-=max(0ll,(l-pos[i]));
    //   cout<<l-pos[i]<<endl;
    } 
    for(int i=1;i<=n;i++){
        if(pos[i]<l){
        }
        for(int k=0;k<=l;k++){
            if(pos[i]-1-k<0) ps[i].val=ps[i].val*2;
            else if((a[i])&(1ll<<(pos[i]-1-k))){
                ps[i].val=ps[i].val*2+1;
            }
            else{
                ps[i].val=ps[i].val*2;
            }
        }
        ps[i].pos=i;
    }
    sort(ps+1,ps+n+1,cmp);
    //cout<<"s="<<s<<endl;
    // for(int i=1;i<=n;i++){
    //     cout<<l-pos[i]<<endl;
    // }
    ll cnt=s;
    //cout<<"s="<<s<<endl;
    for(int i=1;i<=n&&cnt>0;i++){
        pos[ps[i].pos]--;cnt--;
        //cout<<"cnt="<<cnt<<endl;
        if(!cnt) break;
    } 
    ll ans=0;
    for(int i=1;i<=n;i++){
       // cout<<l-pos[i]<<endl;
        ans=(ans+a[i]%mod*ksm(2ll,max(l-pos[i],0ll))%mod)%mod;
    }
    //cout<<"hh"<<endl;
    cout<<ans%mod<<endl;
    return 0;
}
/*
3 1
7 2 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7632kb

input:

3 3
7 2 1

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: -100
Wrong Answer
time: 62ms
memory: 12848kb

input:

200000 1605067
366760624 67854 93901 693975 27016 1046 10808 6533158 54778 500941023 77236442 32173 10431454 2 9726 1553148 89282 411182309 494073 131299543 249904771 7906930 353 9909 3632698 29156 1917186 303 737 1189004 22 1983 263 711 4106258 2070 36704 12524642 5192 123 2061 22887 66 380 1 10153...

output:

888550804

result:

wrong answer 1st numbers differ - expected: '707034173', found: '888550804'