結果

問題 No.2300 Substring OR Sum
ユーザー Yilin Fei
提出日時 2024-01-08 18:06:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 168,448 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-27 19:38:12
合計ジャッジ時間 3,355 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) cin >> A[i];
    ll ans = 0;
    for (ll d = 0; d < 28; d++) {
        ll tmp = (N * (N + 1)) / 2;
        ll c = 0;
        for (ll i = 0; i <= N; i++) {
            if (i == N || (A[i] & (1 << d)) != 0) {
                tmp -= (c * (c + 1)) / 2;
                c = 0;
            } else {
                c++;
            }
        }
        ans += tmp * (1LL << d);
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    solve();
}
0