QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#415026#1817. AND Permutationship2077TL 0ms0kbC++141.1kb2024-05-20 08:20:162024-05-20 08:20:16

Judging History

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

  • [2024-05-20 08:20:16]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

6
0
1
4
5
2
6

output:


result: