1 条题解

  • 0
    @ 2024-4-1 17:33:30
    #include <bits/stdc++.h>
     // #define int long long
    #define help {cin.tie(NULL); cout.tie(NULL);}
    #define pb push_back
    #define fi first
    #define se second
    #define mkp make_pair
    using namespace std;
     
    typedef long long LL;
    typedef pair<int, int> PII;
    typedef pair<LL, LL> PLL;
     
    template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
    template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
     
    template <typename T> void inline read(T &x) {
        int f = 1; x = 0; char s = getchar();
        while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
        while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
        x *= f;
    }
    
    const int N=1e5+5;
    int n,a[N];
    LL s[3],sum;
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i];
        for(int i=0;i<30;i++)
        {
        	int even=0,odd=0;
        	LL cnt[3]={0};
        	int add=0;
        	int one=0;
        	for(int j=1;j<=n;j++)
        		if(a[j]>>i&1)
        		{
        			cnt[0]+=++even;
        			swap(even,odd);
        			cnt[1]+=++add;
        			cnt[2]+=j;
        			one=j;
        		}
        		else
        			cnt[0]+=odd,even++,add=0,cnt[2]+=one;
        	s[0]+=(LL)cnt[0]*(1<<i);
        	s[1]+=(LL)cnt[1]*(1<<i);
        	s[2]+=(LL)cnt[2]*(1<<i);
        }
        printf("%.3lf %.3lf %.3lf",(double)(s[0]*2-sum)/((LL)n*n),(double)(s[1]*2-sum)/((LL)n*n),(double)(s[2]*2-sum)/((LL)n*n));
        return 0;
    }
    
    • 1

    信息

    ID
    127
    时间
    1000ms
    内存
    128MiB
    难度
    10
    标签
    递交数
    6
    已通过
    4
    上传者