QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#472418#1436. Split in SetszbrcCompile Error//C++141.7kb2024-07-11 16:18:062024-07-11 16:18:07

Judging History

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

  • [2024-07-11 16:18:07]
  • 评测
  • [2024-07-11 16:18:06]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e6+10,mod=1e9+7;
int n,k,ans;
multiset<int>a;
int inv[N],fac[N];
int Pow(int x,int n){
	if(n==0)return 1;
	int a=Pow(x,n/2);
	return a*a%mod*(n&1?x:1)%mod;
}
void init(){
	inv[0]=fac[0]=1;
	for(int i=1;i<N;i++)fac[i]=fac[i-1]*i%mod;
	inv[N-1]=Pow(fac[N-1],mod-2);
	for(int i=N-2;i;i--)inv[i]=inv[i+1]*(i+1)%mod;
}
int P(int n,int m){
	return fac[n]*inv[n-m]%mod;
}
int C(int n,int m){
	if(m<0)return 0;
	int res=0;
	for(int i=0;i<=m;i++){
		if((m-i)&1)res=(res+mod-Pow(i,n)*inv[i]%mod*inv[m-i]%mod)%mod;
		else res=(res+Pow(i,n)*inv[i]%mod*inv[m-i]%mod)%mod;
	}
	return res;
}
int tot=1;
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>k;
	init();
	tot=tot*P(k,k);
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		a.insert(x);
	}
	if(k==1){
		ans=*a.begin();
		for(auto i : a)ans&=i;
		cout<<ans<<' '<<1;
		return 0;
	}
	vector<int>e;
	for(int i=40;i>=0;i--){
		int cnt=0,len=a.size();
		e.clear();
		for(auto j : a){
			if((j>>i)&1){
				cnt++;
				e.push_back(j);
			}
		}
		if(cnt==a.size())ans+=min(k,cnt)*(1LL<<i);
		else ans+=min((k-1),cnt)*(1LL<<i);
		if(i==0){
			if(cnt<k)tot=tot*C(a.size()-cnt,k-cnt)%mod;
			else tot=C(cnt+1,k)*tot%mod;
		}
		if(cnt<k){
			k-=cnt;
			for(int j=0;j<e.size();j++){
				ans+=e[j]&((1LL<<i)-1); 
				a.erase(a.lower_bound(e[j]));
			}
		}else{
			int s=INT_MAX;
			for(auto j = a.rbegin();j != a.rend();j++){
				if(lower_bound(e.begin(),e.end(),*j)==e.end()){
					else s&=*j;
					a.erase(a.lower_bound(*j));
				}
			}
			if(cnt!=len)a.insert(s);
		}
	}
	cout<<ans<<' '<<tot<<'\n';
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:73:41: error: expected ‘}’ before ‘else’
   73 |                                         else s&=*j;
      |                                         ^~~~
answer.code:72:79: note: to match this ‘{’
   72 |                                 if(lower_bound(e.begin(),e.end(),*j)==e.end()){
      |                                                                               ^
answer.code:77:46: error: ‘s’ was not declared in this scope
   77 |                         if(cnt!=len)a.insert(s);
      |                                              ^
answer.code: At global scope:
answer.code:80:9: error: ‘cout’ does not name a type
   80 |         cout<<ans<<' '<<tot<<'\n';
      |         ^~~~
answer.code:81:9: error: expected unqualified-id before ‘return’
   81 |         return 0;
      |         ^~~~~~
answer.code:82:1: error: expected declaration before ‘}’ token
   82 | }
      | ^