• Codeforces Global Round 8 D


    #include<map>
    #include<queue>
    #include<time.h>
    #include<limits.h>
    #include<cmath>
    #include<ostream>
    #include<iterator>
    #include<set>
    #include<stack>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define rep_1(i,m,n) for(int i=m;i<=n;i++)
    #define mem(st) memset(st,0,sizeof st)
    int read()
    {
        int res=0,ch,flag=0;
        if((ch=getchar())=='-')             //判断正负
            flag=1;
        else if(ch>='0'&&ch<='9')           //得到完整的数
            res=ch-'0';
        while((ch=getchar())>='0'&&ch<='9')
            res=res*10+ch-'0';
        return flag?-res:res;
    }
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef unsigned long long ull;
    typedef pair<double,double> pdd;
    const int inf = 0x3f3f3f3f;
    const int N = 1000100;
    int n;
    int a[N], cnt[N];
    int main()
    {
        //1具有传递性,那么就把1尽量往大的数字上传
        n = read();
        for (int i = 1; i <= n; i ++)
        {
            a[i] = read();
            for (int j = 0; j <= 20; j ++)
                if (a[i] >> j & 1) cnt[j] ++;
        }
        long long ans = 0;
        for (int i = 1, tar; i <= n; i ++)
        {
            tar = 0;
            for (int j = 0; j <= 20; j ++)
                if (cnt[j])
                    tar |= (1 << j), cnt[j] --;
            ans += 1ll * tar * tar;
        }
        printf("%lld
    ", ans);
        return 0;
    }
  • 相关阅读:
    Python去掉字符串中空格的方法
    python:list
    python3元组
    定时任务cron
    python字典:(Dictionary)操作详解
    SQL语句-基础
    linux免密码登陆
    linux开机故障解决方法
    您应升级到 MySQL 5.5.0 或更高版本。 phpmyadmin
    mysql忘记密码
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/13171961.html
Copyright © 2020-2023  润新知