結果
問題 | No.2300 Substring OR Sum |
ユーザー |
![]() |
提出日時 | 2024-11-08 00:45:47 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 130 ms / 2,000 ms |
コード長 | 726 bytes |
コンパイル時間 | 2,195 ms |
コンパイル使用メモリ | 206,064 KB |
実行使用メモリ | 6,480 KB |
最終ジャッジ日時 | 2024-11-08 00:45:52 |
合計ジャッジ時間 | 4,755 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}int main() {fast_io();int n;cin >> n;vector<int> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}long long ans = 0;for (int i = 0; i < 28; i++) {vector<int> b;for (int j = 0; j < n; j++) {b.push_back((a[j] >> i) & 1);}long long tmp = (long long)n * (n + 1) / 2;vector<pair<int, int>> rle;for (int j : b) {if (rle.empty() || rle.back().first != j) {rle.push_back({j, 1});} else {rle.back().second++;}}for (auto [j, k] : rle) {if (j == 0) {tmp -= (long long)k * (k + 1) / 2;}}ans += tmp << i;}cout << ans << endl;}