QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#415026 | #1817. AND Permutation | ship2077 | TL | 0ms | 0kb | C++14 | 1.1kb | 2024-05-20 08:20:16 | 2024-05-20 08:20:16 |
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=2e5+5,mod=1e9+7;
int n,m,sum,cnt[32];unsigned a[M];
unsigned long long ans;bool fl;
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
int qpow(int x,int n){
int s=1; while (n){
if (n&1) s=1ll*s*x%mod;
x=1ll*x*x%mod; n>>=1;
} return s;
}
int main(){
n=read();m=read();
for (int i=1;i<=n;i++)
a[i]=read(),cnt[31^__builtin_clz(a[i])]++;
for (int k=0;k<30;k++){
sum+=cnt[k];
if (sum<=m) m-=sum;
else{
for (int i=1;i<=n;i++){
int lg=31^__builtin_clz(a[i]);
if (lg<=k) a[i]<<=k-lg;
}
sort(a+1,a+n+1);
for (int i=1;i<=m;i++) a[i]<<=1;
fl=1; break;
}
}
if (!fl) for (int i=1;i<=n;i++) a[i]<<=__builtin_clz(a[i])-1;
sort(a+1,a+n+1);
for (int i=1;i<=m%n;i++) a[i]<<=1;
int i=1;
for (;i+7<=n;ans%=mod,i+=8)
ans+=a[i],ans+=a[i+1],
ans+=a[i+2],ans+=a[i+3],
ans+=a[i+4],ans+=a[i+5],
ans+=a[i+6],ans+=a[i+7];
for (;i<=n;i++) ans+=a[i]; ans%=mod;
return printf("%d\n",ans*qpow(2,m/n)%mod),0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
6 0 1 4 5 2 6