結果

問題 No.911 ラッキーソート
ユーザー otamay6otamay6
提出日時 2019-10-19 13:14:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,870 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 167,416 KB
実行使用メモリ 4,704 KB
最終ジャッジ日時 2023-09-09 08:49:39
合計ジャッジ時間 9,658 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 144 ms
4,704 KB
testcase_14 AC 147 ms
4,668 KB
testcase_15 AC 145 ms
4,620 KB
testcase_16 AC 151 ms
4,572 KB
testcase_17 AC 150 ms
4,616 KB
testcase_18 AC 149 ms
4,672 KB
testcase_19 AC 148 ms
4,576 KB
testcase_20 AC 146 ms
4,572 KB
testcase_21 AC 149 ms
4,568 KB
testcase_22 AC 147 ms
4,684 KB
testcase_23 AC 136 ms
4,416 KB
testcase_24 AC 125 ms
4,376 KB
testcase_25 AC 79 ms
4,376 KB
testcase_26 AC 61 ms
4,376 KB
testcase_27 AC 29 ms
4,376 KB
testcase_28 AC 16 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 149 ms
4,608 KB
testcase_39 AC 143 ms
4,392 KB
testcase_40 AC 5 ms
4,376 KB
testcase_41 AC 148 ms
4,616 KB
testcase_42 AC 96 ms
4,376 KB
testcase_43 AC 147 ms
4,564 KB
testcase_44 AC 127 ms
4,564 KB
testcase_45 AC 131 ms
4,576 KB
testcase_46 AC 131 ms
4,568 KB
testcase_47 AC 129 ms
4,568 KB
testcase_48 AC 125 ms
4,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
int roundup(int a,int b){return	(a-1)/b+1;}

signed main(){
	int N,L,R;cin>>N>>L>>R;
	vector<int> A(N);
	rep(i,N) cin>>A[i];
	int dig[62];
	rep(i,62) dig[i]=2;
	auto dic=[&](auto &&f,int l,int r,int bit)->bool{
		if(l==r) return true;
		if(bit==-1) return false;
		int flag=0,m=l;
		rep(i,l,r){
			if((A[i]>>bit&1)!=(A[i+1]>>bit&1)){
				flag++;
				m=i;
			}
		}
		if(flag>=2) return false;
		if(flag==1){
			if(A[l]>>bit&1){
				if(dig[bit]!=0) dig[bit]=1;
				else return false;
			}
			else{
				if(dig[bit]!=1) dig[bit]=0;
				else return false;
			}
			return f(f,l,m,bit-1)&&f(f,m+1,r,bit-1);
		}
		return f(f,l,r,bit-1);
	};
	if(!dic(dic,0,N-1,61)){
		cout<<0<<endl;
		return 0;
	}
	//rep(i,62) cout<<dig[i]<<" \n"[i==61];
	auto ans=[&](int U){
		if(U==-1) return 0LL;
		int dp[63][2]={};
		dp[62][1]=1;
		for(int i=61;i>=0;--i){
			dp[i][0]=dp[i+1][0];
			if(dig[i]==2){
				if(U>>i&1){
					dp[i][0]=2*dp[i+1][0]+dp[i+1][1];
					dp[i][1]=dp[i+1][1];
				}
				else{
					dp[i][0]=2*dp[i+1][0];
					dp[i][1]=dp[i+1][1];
				}
			}
			if(dig[i]==1){
				if(U>>i&1){
					dp[i][1]=dp[i+1][1];
				}
			}
			if(dig[i]==0){
				if(U>>i&1){
					dp[i][0]+=dp[i+1][1];
				}
				else{
					dp[i][1]=dp[i+1][1];
				}
			}
		}
		return dp[0][0]+dp[0][1];
	};
	cout<<ans(R)-ans(L-1)<<endl;
}
0