結果

問題 No.2300 Substring OR Sum
ユーザー kotatsugame
提出日時 2023-05-12 21:28:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 460 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 64,256 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 17:19:46
合計ジャッジ時間 2,204 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
int N,A[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	long long ans=0;
	for(int k=0;k<28;k++)
	{
		int prv=0;
		long long now=(long long)N*(N+1)/2;
		for(int i=0;i<N;i++)if(A[i]>>k&1)
		{
			int len=i-prv;
			now-=(long long)len*(len+1)/2;
			prv=i+1;
		}
		{
			int len=N-prv;
			now-=(long long)len*(len+1)/2;
		}
		ans+=now<<k;
	}
	cout<<ans<<endl;
}
0