結果
問題 | No.2300 Substring OR Sum |
ユーザー |
![]() |
提出日時 | 2023-03-13 20:53:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 168 ms / 2,000 ms |
コード長 | 581 bytes |
コンパイル時間 | 1,971 ms |
コンパイル使用メモリ | 196,436 KB |
最終ジャッジ日時 | 2025-02-11 11:00:16 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#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";}