結果

問題 No.911 ラッキーソート
ユーザー milanis48663220milanis48663220
提出日時 2020-10-27 02:02:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,901 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 85,048 KB
実行使用メモリ 5,436 KB
最終ジャッジ日時 2023-09-29 03:08:51
合計ジャッジ時間 9,457 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,984 KB
testcase_01 AC 2 ms
4,988 KB
testcase_02 AC 2 ms
4,988 KB
testcase_03 AC 2 ms
4,968 KB
testcase_04 AC 2 ms
5,040 KB
testcase_05 AC 2 ms
4,968 KB
testcase_06 AC 1 ms
4,972 KB
testcase_07 AC 2 ms
4,972 KB
testcase_08 AC 2 ms
4,968 KB
testcase_09 AC 2 ms
5,036 KB
testcase_10 AC 2 ms
4,976 KB
testcase_11 AC 1 ms
4,972 KB
testcase_12 AC 1 ms
4,968 KB
testcase_13 AC 96 ms
5,168 KB
testcase_14 AC 96 ms
5,436 KB
testcase_15 AC 93 ms
5,168 KB
testcase_16 AC 96 ms
5,156 KB
testcase_17 AC 95 ms
5,160 KB
testcase_18 AC 94 ms
5,312 KB
testcase_19 AC 93 ms
5,248 KB
testcase_20 AC 89 ms
5,096 KB
testcase_21 AC 83 ms
5,212 KB
testcase_22 AC 79 ms
5,040 KB
testcase_23 AC 74 ms
4,972 KB
testcase_24 AC 67 ms
5,032 KB
testcase_25 AC 40 ms
4,972 KB
testcase_26 AC 34 ms
4,988 KB
testcase_27 AC 16 ms
5,036 KB
testcase_28 AC 9 ms
4,968 KB
testcase_29 AC 4 ms
4,988 KB
testcase_30 AC 2 ms
4,968 KB
testcase_31 AC 1 ms
4,988 KB
testcase_32 AC 2 ms
4,972 KB
testcase_33 AC 2 ms
5,032 KB
testcase_34 AC 2 ms
5,032 KB
testcase_35 AC 1 ms
4,972 KB
testcase_36 AC 2 ms
4,784 KB
testcase_37 AC 2 ms
4,988 KB
testcase_38 AC 96 ms
5,316 KB
testcase_39 AC 78 ms
5,292 KB
testcase_40 AC 4 ms
5,036 KB
testcase_41 AC 91 ms
5,092 KB
testcase_42 AC 53 ms
4,968 KB
testcase_43 AC 96 ms
5,240 KB
testcase_44 AC 40 ms
4,988 KB
testcase_45 AC 41 ms
4,996 KB
testcase_46 AC 41 ms
5,004 KB
testcase_47 AC 39 ms
5,040 KB
testcase_48 AC 39 ms
5,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int n;
ll l, r;
ll a[200000];
bool ok0[61];
bool ok1[61];

void input(){
    cin >> n >> l >> r;
    for(int i = 0; i < n; i++) cin >> a[i];
}

bool change[200000];
ll dp[64][2];

ll calc(ll x){
    if(x < 0) return 0;
    for(int j = 60; j >= 0; j--){
        dp[j][0] = 0;
        dp[j][1] = 0;
    }
    dp[61][1] = 1;
    for(int j = 60; j >= 0; j--){
        ll m = (ll)1<<j;
        if(x&m){ 
            if(ok0[j]) {
                dp[j][0] += dp[j+1][0]+dp[j+1][1];
            }
            if(ok1[j]){
                dp[j][0] += dp[j+1][0];
                dp[j][1] += dp[j+1][1];
            }
        }else{
            if(ok0[j]) {
                dp[j][0] += dp[j+1][0];
                dp[j][1] += dp[j+1][1];
            }
            if(ok1[j]){
                dp[j][0] += dp[j+1][0];
            }
        }
        // cout << dp[j][0]+dp[j][1] << endl;
    }
    return dp[0][0]+dp[0][1];
}

void solve(){
    for(int j = 60; j >= 0; j--){
        vector<bool> ok(2, true);
        ll m = (ll)1<<j;
        for(int i = 1; i < n; i++){
            if((m&a[i]) != (m&a[i-1])){
                // cout << j << ' ' << i << endl;
                if(change[i]) {
                    continue;
                }
                change[i] = true;
                if(!(m&a[i])) ok[0] = false;
                else ok[1] = false;
            }
        }
        if(!(ok[0] || ok[1])){
            cout << 0 << endl;
            return;
        }
        ok0[j] = ok[0];
        ok1[j] = ok[1];
        // cout << ok[0] << ' ' << ok[1] << endl;
    }
    cout << calc(r)-calc(l-1) << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    input();
    solve();
}
0