結果

問題 No.2300 Substring OR Sum
ユーザー erbowlerbowl
提出日時 2023-05-12 21:42:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 513 ms / 2,000 ms
コード長 3,341 bytes
コンパイル時間 2,477 ms
コンパイル使用メモリ 205,440 KB
実行使用メモリ 50,116 KB
最終ジャッジ日時 2024-05-06 11:29:31
合計ジャッジ時間 6,992 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 124 ms
10,112 KB
testcase_04 AC 103 ms
8,832 KB
testcase_05 AC 143 ms
10,240 KB
testcase_06 AC 72 ms
6,912 KB
testcase_07 AC 443 ms
26,436 KB
testcase_08 AC 178 ms
12,976 KB
testcase_09 AC 150 ms
10,752 KB
testcase_10 AC 356 ms
21,588 KB
testcase_11 AC 412 ms
24,528 KB
testcase_12 AC 436 ms
26,636 KB
testcase_13 AC 513 ms
50,116 KB
testcase_14 AC 37 ms
5,376 KB
testcase_15 AC 187 ms
13,508 KB
testcase_16 AC 355 ms
21,632 KB
testcase_17 AC 431 ms
26,088 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long
// こっちを使おう!
// __builtin_popcountll

// modint
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() const { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD>& r, long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return modpow(modinv(r), -n);
        auto t = modpow(r, n / 2);
        t = t * t;
        if (n & 1) t = t * r;
        return t;
    }
    friend constexpr Fp<MOD> modinv(const Fp<MOD>& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Fp<MOD>(u);
    }
};

// const int MOD = 1000000007;
const int MOD = 998244353;
using mint = Fp<MOD>;


signed main(){
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    vector<vector<ll>> loc(28);
    for (int i = 0; i < 28; i++) {
        for (int j = 0; j < n; j++) {
            if(a[j]&(1ll<<i)){
                loc[i].push_back(j);
            }
        }
    }
    ll ans = 0;
    
    for (int i = 0; i < 28; i++) {
        for (int j = 0; j < n; j++) {
            auto it = lower_bound(loc[i].begin(),loc[i].end(),j);
            if(it==loc[i].end())continue;
            ans += (n-(*it))*(1ll<<i);
        }
        // std::cout << ans << std::endl;
    }
    std::cout << ans << std::endl;
}
0