結果
問題 | No.2300 Substring OR Sum |
ユーザー |
![]() |
提出日時 | 2023-05-12 21:29:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 113 ms / 2,000 ms |
コード長 | 1,040 bytes |
コンパイル時間 | 1,302 ms |
コンパイル使用メモリ | 112,376 KB |
最終ジャッジ日時 | 2025-02-12 22:02:48 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <map>#include <queue>#include <set>#include <random>#include <iomanip>#include <string>#include <cmath>#include <complex>using namespace std;typedef long long ll;#define rep(i, n) for(int i = 0; i < (n); i++)template<class T>using vi = vector<T>;template<class T>using vii = vector<vi<T>>;template<class T>using viii = vector<vii<T>>;using P = pair<ll, int>;void chmin(ll & x, ll y) { x = min(x, y); }void chmax(ll& x, ll y) { x = max(x, y); }int main(){ll n;cin >> n;vi<ll> a(n);rep(i, n) cin >> a[i];ll ans = 0;const int mx = 28;rep(i, mx) {ll cnt = 0;ans += (1LL << i) * n * (n + 1) / 2;rep(j, n) {if (a[j] >> i & 1) {ans -= (1LL << i) * cnt * (cnt + 1) / 2;cnt = 0;}else cnt++;}if (cnt) ans -= (1LL << i) * cnt * (cnt + 1) / 2;}cout << ans << endl;return 0;}