求助!!!10分
查看原帖
求助!!!10分
847548
csh0908楼主2024/8/13 21:48
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e7+10;
int n,a[N],x,w[N],ans;
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
template <typename T>
inline void read(T& r) {
	r=0;bool w=0; char ch=getchar();
	while(ch<'0'||ch>'9') w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9') r=r*10+(ch^48), ch=getchar();
	r=w?-r:r;
}
signed main(){
    read(n);
    for(int i=1;i<=n;i++)
    {
    	read(x);
    	if(x==0)
		{
			ans++;
			continue;
		}
    	int l=0,r=61;
    	int mid=(l+r)/2;
    	while(l+1<r)
    	{
    		mid=(l+r)/2;
    		if((1<<mid)>x)r=mid;
    		else l=mid;
//    		cout<<1;
    	}
    	w[l]=1;
    	a[l]|=x;
	}	
    for(int i=0;i<=60;i++)
    {
    	if(w[i])
    	{
    		ans++;
    		for(int j=i+1;j<=60;j++)
    			if(a[j]&a[i])
    			{
    				ans--;
    				a[j]|=a[i];
    				break;
    			}
    	}
    }
    cout<<ans;
    return 0;
}

只A了#1#6#7,其他WA,10分求调

2024/8/13 21:48
加载中...