QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#419849 | #8723. 乘二 | debate | WA | 58ms | 9956kb | C++14 | 2.2kb | 2024-05-24 11:57:48 | 2024-05-24 11:57:49 |
Judging History
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;
}
//cout<<"s="<<s<<endl;
ll tot=0;
for(int i=1;i<=n;i++){
if(pos[i]<l){
++tot;
for(int k=0;k<=l;k++){
if(pos[i]-1-k<0) ps[tot].val=ps[tot].val*2;
else if((a[i])&(1ll<<(pos[i]-1-k))){
ps[tot].val=ps[tot].val*2+1;
}
else{
ps[tot].val=ps[tot].val*2;
}
}
ps[tot].pos=i;
}
}
sort(ps+1,ps+tot+1,cmp);
//cout<<"s="<<s<<endl;
// for(int i=1;i<=tot;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 5
7 2 1
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7788kb
input:
3 3 7 2 1
output:
15
result:
ok 1 number(s): "15"
Test #2:
score: -100
Wrong Answer
time: 58ms
memory: 9956kb
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:
792201632
result:
wrong answer 1st numbers differ - expected: '707034173', found: '792201632'