QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#421575 | #8723. 乘二 | liusy | TL | 1ms | 3632kb | C++14 | 2.0kb | 2024-05-25 21:39:03 | 2024-05-25 21:39:03 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
const int N=200010;
const ll mod=1e9+7;
struct node{
ll a, n, mi;
}arr[N];
bool cmp(node a, node b){
return a.a < b.a;
}
bool cmpmi(node a, node b){
int ai = -1, bi = -1;
int da = a.a, db = b.a;
while(da){
ai ++;
da >>= 1;
}
while(db){
bi ++;
db >>= 1;
}
if(ai == bi){
return a.n < b.n;
}
else if(ai > bi){
return a.n < b.n - (ai - bi);
}
else{
return a.n - (bi - ai) < b.n;
}
}
int main(){
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i ++){
scanf("%lld", &arr[i].a);
}
sort(arr + 1, arr + n + 1, cmp);
int maxx = arr[n].a, maxi = -1;
while(maxx){
maxi ++;
maxx >>= 1;
}
for(int i = 1; i < n; i ++){
int maxx = arr[n].a;
int tmp = arr[i].a;
int cnt = 0;
while(1 << maxi > tmp){
cnt ++;
tmp <<= 1;
//cout << "?";
}
arr[i].mi = cnt;
}
while(k --){
if(arr[1].mi == 0){
break;
}
arr[1].mi -= 1;
arr[1].n += 1;
sort(arr + 1, arr + n + 1, cmpmi);
}
sort(arr + 1, arr + n + 1, cmpmi);
if(k){
int tk = k / n;
k = k % n;
for(int i = 1; i <= n; i ++){
arr[i].n += tk;
}
for(int i = 1; i <= k; i ++){
arr[i].n += 1;
}
}
ll ans = 0;
for(int i = 1; i <= n; i ++){
int ai = arr[i].a, cnt = arr[i].n;
int tmp = 1, t = 2;
while(cnt){
if(cnt & 1){
tmp = (tmp * t) % mod;
}
t = t * t % mod;
cnt >>= 1;
}
tmp = tmp * ai % mod;
ans = ans + tmp % mod;
}
cout << ans;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
input:
3 3 7 2 1
output:
15
result:
ok 1 number(s): "15"
Test #2:
score: -100
Time Limit Exceeded
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...