結果

問題 No.911 ラッキーソート
ユーザー ats5515ats5515
提出日時 2019-10-18 23:04:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,643 bytes
コンパイル時間 1,990 ms
コンパイル使用メモリ 78,488 KB
実行使用メモリ 4,776 KB
最終ジャッジ日時 2023-09-08 01:42:55
合計ジャッジ時間 4,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 57 ms
4,688 KB
testcase_14 AC 58 ms
4,560 KB
testcase_15 AC 58 ms
4,672 KB
testcase_16 AC 60 ms
4,564 KB
testcase_17 AC 59 ms
4,660 KB
testcase_18 AC 60 ms
4,776 KB
testcase_19 AC 60 ms
4,568 KB
testcase_20 AC 60 ms
4,624 KB
testcase_21 AC 62 ms
4,572 KB
testcase_22 AC 63 ms
4,628 KB
testcase_23 AC 60 ms
4,376 KB
testcase_24 AC 55 ms
4,376 KB
testcase_25 AC 36 ms
4,380 KB
testcase_26 AC 29 ms
4,376 KB
testcase_27 AC 15 ms
4,380 KB
testcase_28 AC 9 ms
4,376 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 58 ms
4,636 KB
testcase_39 AC 62 ms
4,644 KB
testcase_40 AC 4 ms
4,380 KB
testcase_41 AC 60 ms
4,648 KB
testcase_42 AC 41 ms
4,376 KB
testcase_43 AC 58 ms
4,564 KB
testcase_44 AC 56 ms
4,700 KB
testcase_45 AC 59 ms
4,608 KB
testcase_46 AC 59 ms
4,560 KB
testcase_47 AC 57 ms
4,684 KB
testcase_48 AC 60 ms
4,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int B = 61;
int solve(int m0, int m1, int X) {
	if (X < 0)return 0;
	vector<int> C(B, 0);
	for (int i = 0; i < B; i++) {
		int bit = ((int)1 << i);
		if (!(bit & (m0 | m1))) {
			C[i]++;
		}
		if (i > 0)C[i] += C[i - 1];
	}
	int res = 0;
	int t = 1;
	for (int i = B - 1; i >= 0; i--) {
		int bit = ((int)1 << i);
		
		if ((m0 & bit)) {
			if (X & bit) {
				if (i > 0) {
					res += ((int)1 << (C[i - 1]));
				}
				else {
					res++;
				}
				t = 0;
				break;
			}
		}
		else if ((m1 & bit)) {
			if (!(X & bit)) {
				t = 0;
				break;
			}
		}
		else {
			if (X & bit) {
				if (i > 0) {
					res += ((int)1 << (C[i - 1]));
				}
				else {
					res++;
				}
			}
		}
	}
	res += t;
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, L, R;
	cin >> N >> L >> R;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	int m1 = 0;
	int m0 = 0;
	for (int i = 1; i < N; i++){
		for (int j = B - 1; j >= 0; j--) {
			int bit = ((int)1 << j);
			if (!(A[i - 1] & bit) && (A[i] & bit)) {
				m0 |= bit;
				//cerr << 0 << " " << j << endl;
				break;
			}
			else if ((A[i - 1] & bit) && !(A[i] & bit)) {
				m1 |= bit;
				//cerr << 1 << " " << j << endl;
				break;
			}
			if (j == 0) {
				m0 |= 1;
				m1 |= 1;
			}
		}
	}
	if (m0 & m1) {
		res = 0;
	}
	else {
		res = solve(m0, m1, R) - solve(m0, m1, L - 1);
	}

	cout << res << endl;
}
0