結果
問題 |
No.2300 Substring OR Sum
|
ユーザー |
![]() |
提出日時 | 2023-05-12 21:45:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 302 ms / 2,000 ms |
コード長 | 1,051 bytes |
コンパイル時間 | 1,824 ms |
コンパイル使用メモリ | 198,620 KB |
最終ジャッジ日時 | 2025-02-12 22:27:15 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() template<class T> void chmin(T &a,T b){ if(a>b){ a=b; } } template<class T> void chmax(T &a,T b){ if(a<b){ a=b; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; vector<ll> a(n); vector<vector<ll>> v(30,vector<ll>(n,0)); rep(i,n){ cin >> a[i]; rep(j,30){ if(a[i]&(1<<j)) v[j][i]++; } } vector<vector<ll>> sum(30,vector<ll>(n+1,0)); rep(i,n){ rep(j,30){ sum[j][i+1]=sum[j][i]+v[j][i]; } } ll ans=0; rep(i,n){ rep(j,30){ if(a[i]&(1<<j)) ans+=(1<<j)*(n-i); else{ ll p=upper_bound(all(sum[j]),sum[j][i])-sum[j].begin(); ans+=(1<<j)*(n+1-p); } } } cout << ans << '\n'; }