結果

問題 No.2300 Substring OR Sum
ユーザー えいるえいる
提出日時 2023-05-12 21:54:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,667 bytes
コンパイル時間 3,998 ms
コンパイル使用メモリ 231,688 KB
実行使用メモリ 6,496 KB
最終ジャッジ日時 2024-05-06 11:43:58
合計ジャッジ時間 5,985 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 35 ms
5,376 KB
testcase_04 AC 29 ms
5,376 KB
testcase_05 AC 36 ms
5,376 KB
testcase_06 AC 19 ms
5,376 KB
testcase_07 AC 114 ms
6,180 KB
testcase_08 AC 49 ms
5,376 KB
testcase_09 AC 39 ms
5,376 KB
testcase_10 AC 87 ms
5,760 KB
testcase_11 AC 103 ms
5,916 KB
testcase_12 AC 115 ms
6,400 KB
testcase_13 AC 98 ms
6,400 KB
testcase_14 AC 48 ms
6,496 KB
testcase_15 AC 51 ms
5,376 KB
testcase_16 AC 89 ms
5,592 KB
testcase_17 AC 112 ms
6,284 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vvvl=vector<vector<vector<long long>>>;
using pl=pair<long long,long long>;
using vpl=vector<pair<long long,long long>>;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#include <atcoder/all>
using namespace atcoder;

long long modpow(long long a, long long n, long long mo){long long res=1;while(n>0){if(n&1){res=res*a%mo;}a=a*a%mo;n>>=1;}return res;}
long long Pow(long long a, long long n){long long res=1;while(n>0){if(n&1){res=res*a;}a=a*a;n>>=1;}return res;}
//ランレングス圧縮
vector<pair<char, long long>> encode(const string &str){
  int n=(int)str.size();
  vector<pair<char, long long>> ret; // 答えを格納
  for (int l = 0; l < n;) {
    int r = l + 1;
    for (; r < n && str[l] == str[r]; r++) {};
    ret.push_back({str[l], r-l});
    l = r;
  }
  return ret;
}
const ll MOD=998244353;
const ll INF=(1ll<<60);
int main(){
  ll N;
  cin>>N;
  vl A(N);
  rep(i,N) cin>>A[i];
  ll fina=0;
  rep(i,28){
    vl A2(N+1,1);
    rep(j,N) A2[j]=(A[j]>>i)%2;
    ll ans=0;
    ll next=0;
    ll sum=0;
    while(next<N+1){
      if(A2[next]==1){
        ans+=(sum*(sum+1))/2;
        next++;
        sum=0;
      }
      else{
        sum++;
        next++;
      }
    }
    fina+=(1<<i)*((N*(N+1))/2-ans);
  }
  cout<<fina<<endl;
}
0