結果

問題 No.2300 Substring OR Sum
ユーザー stoqstoq
提出日時 2023-03-13 20:53:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 581 bytes
コンパイル時間 1,892 ms
コンパイル使用メモリ 202,728 KB
実行使用メモリ 8,172 KB
最終ジャッジ日時 2023-08-19 03:22:34
合計ジャッジ時間 4,196 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 36 ms
4,380 KB
testcase_04 AC 29 ms
4,384 KB
testcase_05 AC 36 ms
4,380 KB
testcase_06 AC 18 ms
4,380 KB
testcase_07 AC 118 ms
6,304 KB
testcase_08 AC 52 ms
4,380 KB
testcase_09 AC 38 ms
4,380 KB
testcase_10 AC 96 ms
5,656 KB
testcase_11 AC 115 ms
6,248 KB
testcase_12 AC 121 ms
6,296 KB
testcase_13 AC 131 ms
8,172 KB
testcase_14 AC 32 ms
4,644 KB
testcase_15 AC 55 ms
4,408 KB
testcase_16 AC 99 ms
5,712 KB
testcase_17 AC 118 ms
6,248 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  ll sum = 0;
  for (int bit = 0; bit < 28; bit++) {
    vector<ll> pos;
    pos.push_back(-1);
    for (int i = 0; i < n; i++) {
      if (a[i] & (1LL << bit)) pos.push_back(i);
    }
    pos.push_back(n);
    ll cnt = n * (n + 1) / 2;
    for (int i = 0; i + 1 < pos.size(); i++) {
      ll k = pos[i + 1] - pos[i] - 1;
      cnt -= k * (k + 1) / 2;
    }
    sum += (1LL << bit) * cnt;
  }
  cout << sum << "\n";
}
0