結果

問題 No.2300 Substring OR Sum
ユーザー startcppstartcpp
提出日時 2023-05-13 19:52:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 573 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 65,924 KB
実行使用メモリ 48,740 KB
最終ジャッジ日時 2023-08-19 17:14:35
合計ジャッジ時間 3,130 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
46,564 KB
testcase_01 AC 9 ms
46,368 KB
testcase_02 AC 8 ms
46,360 KB
testcase_03 AC 43 ms
47,236 KB
testcase_04 AC 34 ms
47,072 KB
testcase_05 AC 39 ms
47,368 KB
testcase_06 AC 25 ms
46,880 KB
testcase_07 AC 110 ms
48,604 KB
testcase_08 AC 52 ms
47,660 KB
testcase_09 AC 41 ms
47,468 KB
testcase_10 AC 99 ms
48,060 KB
testcase_11 AC 100 ms
48,252 KB
testcase_12 AC 112 ms
48,628 KB
testcase_13 AC 91 ms
48,656 KB
testcase_14 AC 48 ms
48,740 KB
testcase_15 AC 52 ms
47,688 KB
testcase_16 AC 88 ms
47,996 KB
testcase_17 AC 110 ms
48,556 KB
testcase_18 AC 9 ms
46,416 KB
testcase_19 AC 9 ms
46,368 KB
testcase_20 AC 9 ms
46,420 KB
testcase_21 AC 9 ms
46,408 KB
testcase_22 AC 9 ms
46,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//得意
#include <iostream>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int a[200000];
int minR[28][200001];

signed main() {
	int i, j;

	cin >> n;
	rep(i, n) cin >> a[i];

	rep(i, 28) {
		minR[i][n] = n;
		for (j = n - 1; j >= 0; j--) {
			if ((a[j] >> i) % 2 == 1) {
				minR[i][j] = j;
			}
			else {
				minR[i][j] = minR[i][j + 1];
			}
		}
	}

	int ans = 0;
	rep(i, 28) {
		int cnt = 0;
		rep(j, n) {
			cnt += n - minR[i][j];
		}
		ans += cnt * (1LL << i);
	}

	cout << ans << endl;
	return 0;
}
0