結果

問題 No.911 ラッキーソート
ユーザー kotamanegi
提出日時 2019-10-18 21:55:25
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 2,183 bytes
コンパイル時間 1,288 ms
コンパイル使用メモリ 150,136 KB
実行使用メモリ 5,580 KB
最終ジャッジ日時 2024-11-30 15:04:17
合計ジャッジ時間 7,850 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

//カタラン数を語らん!w

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
long long n, l, r;
vector<long long> inputs;
long long calc(long long now) {
	long long must_be[64][2] = {};
	for (long long i = 0; i < inputs.size() - 1; ++i) {
		for (long long q = 61; q >= 0; --q) {
			long long a = ((1LL << q) & inputs[i]);
			long long b = ((1LL << q) & inputs[i + 1]);
			if ((a ^ b) != 0) {
				if (a != 0) {
					must_be[q][1] = 1;
				}
				else {
					must_be[q][0] = 1;
					//bit
				}
				break;
			}
		}
	}
	long long cnt = 0;
	long long ans = 0;
	for (long long i = 61; i >= 0; --i) {
		if (must_be[i][0] + must_be[i][1] == 2) return 0;
		if (must_be[i][0] + must_be[i][1] == 1) {

		}
		else {
			cnt++;
		}
	}
	for (long long q = 61; q >= 0; --q) {
		if (must_be[q][0] + must_be[q][1] == 0) cnt--;
		if (((1LL << q) & now) == 0) {
			//should be 0
			if (must_be[q][1] == 1) {
				return ans;
			}
		}
		else {
			//can be both 0 & 1
			if (must_be[q][0] == 1) {
				return ans + (1LL << cnt);
			}
			else {
				if (must_be[q][1] == 0) {
					ans += 1LL << cnt;
				}
			}
		}
	}
	return ans + 1LL;
}
int main() {
	cin >> n >> l >> r;
	REP(i, n) {
		long long a;
		cin >> a;
		inputs.push_back(a);
	}
	long long ans = calc(r);
	if (l != 0) {
		ans -= calc(l - 1);
	}
	cout << ans << endl;
}
0