Codeforces-1466E Apollo versus Pan


Problem

Portal


Thoughts

取模运算的优先级与乘除一样,大于加减。
而且卡cin时间复杂度卡的特别紧。。
Portal


Accepted Code

#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e6 + 10;
const int mod = 1e9 + 7;

int x[N];
int cnt[70];

signed main()
{
    int T; cin >> T;
    while(T -- )
    {
        memset(cnt, 0, sizeof cnt);
        int n; scanf("%lld", &n);
        for(int i = 1 ; i <= n ; i ++ ) scanf("%lld", &x[i]);

        for(int i = 0 ; i < 61 ; i ++ )
            for(int j = 1 ; j <= n ; j ++ )
                if(x[j]>>i&1) cnt[i] ++ ;

        int ans = 0;
        for(int i = 1 ; i <= n ; i ++ )
        {
            int a = 0, b = 0;
            for(int j = 0 ; j < 61 ; j ++ )
            {
                if(x[i]>>j&1) 
                {
                    a = (a%mod + ((cnt[j]%mod)*((1ll<<j)%mod))%mod)%mod;
                    b = (b%mod + ((n%mod)*((1ll<<j)%mod))%mod)%mod;
                }
                else b = (b%mod + ((cnt[j]%mod)*((1ll<<j)%mod))%mod)%mod;
            }
            ans = (ans%mod + (a%mod * b%mod)%mod)%mod;
        }

        printf("%lld\n", ans%mod);
    }

    return 0;
}

Author: Mrhh
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Mrhh !
评论
 Previous
Codeforces-1462E2 Close Tuples (hard version) Codeforces-1462E2 Close Tuples (hard version)
ProblemPortal Thoughts思路和easy一样,只是求组合数的时候,这里乘积很大,需要取模,但easy的求组合数板子中含有除法,不能取模。所以我们给出当组合数很大时,带取模的组合数板子。(利用乘法逆元除法将转化为乘法)$C
Next 
Codeforces-1467D Sum of Paths Codeforces-1467D Sum of Paths
ProblemPortal Thoughtsdp[i][j]状态表示:走到i点走了j步的方案数。Portal Accepted Code#include <bits/stdc++.h> #define int long long
  TOC