結果

問題 No.911 ラッキーソート
ユーザー polylogKpolylogK
提出日時 2019-10-18 22:15:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 2,108 bytes
コンパイル時間 1,817 ms
コンパイル使用メモリ 170,020 KB
実行使用メモリ 5,696 KB
最終ジャッジ日時 2023-09-07 23:54:57
合計ジャッジ時間 5,456 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 69 ms
5,536 KB
testcase_14 AC 69 ms
5,420 KB
testcase_15 AC 68 ms
5,380 KB
testcase_16 AC 72 ms
5,408 KB
testcase_17 AC 71 ms
5,420 KB
testcase_18 AC 71 ms
5,536 KB
testcase_19 AC 71 ms
5,696 KB
testcase_20 AC 72 ms
5,660 KB
testcase_21 AC 72 ms
5,380 KB
testcase_22 AC 72 ms
5,472 KB
testcase_23 AC 72 ms
5,172 KB
testcase_24 AC 64 ms
5,004 KB
testcase_25 AC 40 ms
4,380 KB
testcase_26 AC 34 ms
4,376 KB
testcase_27 AC 16 ms
4,380 KB
testcase_28 AC 9 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 67 ms
5,408 KB
testcase_39 AC 70 ms
5,264 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 67 ms
5,512 KB
testcase_42 AC 46 ms
4,708 KB
testcase_43 AC 70 ms
5,536 KB
testcase_44 AC 38 ms
5,528 KB
testcase_45 AC 39 ms
5,436 KB
testcase_46 AC 40 ms
5,432 KB
testcase_47 AC 39 ms
5,436 KB
testcase_48 AC 38 ms
5,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; i64 L, R; scanf("%d%lld%lld", &n, &L, &R);
	std::vector<i64> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);

	// 0011 | 0011 | 0011 -> 1 pattern
	// 0011 | 1100 | .... -> inpossiblent i = 0; i < 60; i++) {
	// 0000000 or 1111111 -> 2 pattern
	std::vector<int> kiri(n + 1, false); kiri[n] = true; // 数列切るたん, left)
	std::vector<int> tan(61, 0); // true -> 1 pattern
	for(int k = 60; k >= 0; k--) {
		// x: 1100
		// y: 0011
		// z: 0000 or 1111
		int x = 0, y = 0, z = 0, w = 0;
		for(int i = 0; i < n; i++) {
			if(kiri[i + 1]) {
				if(w > 1) {
					printf("0\n");
					return 0;
				} else if(w == 0) {
					z++;
				}
				w = 0;
				
				continue;
			}
			
			int A = a[i] >> k & 1, B = a[i + 1] >> k & 1;
			if(A == B) continue;

			kiri[i + 1] = true;
			if(A) x++; 
			else y++;
			w++;
		}
		if(x and y) {
			printf("0\n");
			return 0;
		}

		if(x) tan[k] = 1;
		else if(y) tan[k] = 0;
		else tan[k] = -1;
	}
	
	auto calc = [&](i64 t) -> i64 {
		if(t < 0) return 0LL;
	
		auto dp = make_v<i64>(62, 2); dp[0][1] = 1;
		for(int k = 60, i = 0; k >= 0; k--, i++) {
			if(t >> k & 1) {
				if(tan[k] == 0) {
					dp[i + 1][0] += dp[i][0] + dp[i][1];
				} else  if(tan[k] == 1) {
					dp[i + 1][0] += dp[i][0];
					dp[i + 1][1] += dp[i][1];
				} else {
					dp[i + 1][0] += dp[i][0] * 2LL + dp[i][1];
					dp[i + 1][1] += dp[i][1];
				}
			} else {
				if(tan[k] == 0) {
					dp[i + 1][0] += dp[i][0];
					dp[i + 1][1] += dp[i][1];
				} else if(tan[k] == 1) {
					dp[i + 1][0] += dp[i][0];
				} else {
					dp[i + 1][0] += dp[i][0] * 2LL;
					dp[i + 1][1] += dp[i][1];
				}
			}
		}
		return (dp[61][0] + dp[61][1]);
	};
	
	printf("%lld\n", calc(R) - calc(L - 1));
	return 0;
}
0