結果
問題 | No.2300 Substring OR Sum |
ユーザー | NAMIDAIRO |
提出日時 | 2023-05-12 21:29:57 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 1,040 bytes |
コンパイル時間 | 1,192 ms |
コンパイル使用メモリ | 116,136 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-28 17:21:55 |
合計ジャッジ時間 | 3,057 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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; }